Object Oriented Design Principles

Here are few Design Principles should be followed in Object Oriented programming, These are not specific to any programming language.

  1. STUPID
  2. DRY
  3. YAGNI
  4. High Cohesion & Low Coupling
  5. Inversion of Control
  6. Dependency Injection
  7. SOLID principles
  8. SLAP your methods
  9. Anti-Patterns

1. STUPID is a set of principles to avoid while writing code

Singleton

Tight Coupling

Untestability

Premature Optimization

Indescriptive Naming

Duplication

2. DRY ( Don’t Repeat Yourself)

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

The DRY principle states that these small pieces of knowledge may only occur exactly once in your entire system.

example: Lot of copy-paste code found in most of the source code

3. YAGNI (You Aren't Gonna Need It)

Always implement things when you actually need them, never when you just foresee that you need them.

4. High on Cohesion, Low on Coupling

Cohesion is an indication of how related and focused the responsibilities of an software element are.

Cohesion is the indication of the relationship within module.

  • Readability
  • Maintainability
  • Re-usability

Coupling refers to how strongly a software element is connected to other elements.

Coupling is the indication of the relationships between modules.

No alt text provided for this image


5. Inversion of Control (IoC)

Inversion of control refers to the inversion of the flow of control (the order in which individual statements, function calls, etc. are executed) in a software.

“Inversion of Control is an abstract principal describing an aspect of some software architecture design in which the flow of control of a system is inverted in comparison to procedural programming.”

IoC is also known as "Hollywood Principle" with its essence in the statement "Don't call us, we'll call you“

6. Dependency Injection

  • It eliminates tight coupling between objects.
  • Makes objects and application more flexible.
  • It facilitates creating more loosely coupled objects and their dependencies.
No alt text provided for this image





7. S.O.L.I.D principle

SOLID is very popular and widely followed design principles

Single Responsibility Principle

–Every Class should have single responsibility, there should never be more than one reason for a class to change

Open/Closed Principle

–Every Software Entity should be open for extension but closed for modification

LiskovSubstitution Principle

–Objects should always be replaceable with instances of their subtypes without altering their correctness

Interface Segregation Principle

–Many client specific interfaces are better than one general purpose interface, this leads to loose coupling and high cohesion

Dependency Inversion Principle

–Abstraction should not depend upon details, details should depend upon 

8. SLAP (Single Level of Abstraction Principles)

SLAP your methods example:

No alt text provided for this image

9. Anti-Patterns

  • An anti-pattern is a common response to a recurring problem that is usually ineffective and risks being highly counterproductive.
  • An anti-pattern is a way of not solving a problem. But there is more to it: it is also a way that can frequently be seen in attempts to solve the problem.
  • A pattern is an idea of how to solve a problem of some class. An anti-pattern is an idea of how not to solve it because implementing that idea would result in bad design.

Examples of Anti-Patterns:

?God Class/Object -Does everything in One Object

?Copy-Paste programming -Repeated copy paste code

?Spaghetti Code

?Magic Numbers and Strings

good read for anti-patterns: https://sahandsaba.com/nine-anti-patterns-every-programmer-should-be-aware-of-with-examples.html



GovindaRao Gotta

Heading IoT Device Platform and Edge-Cloud Connectivity | Data Acquisition & Device Management Platform | next-gen Edge Devices | Digital Transformation essentials.

5 年

Nice capture! Thank you.

回复
Gaurav Khatri

Ingenieur développement logiciel embarqué expert

5 年

perfect pointers on how? to save? post programming time. looking forward for more articles .

Ravi Thakur

Product Design & Development for Industrial Automation.

5 年

Please drop these theories and start actual work ??

回复

要查看或添加评论,请登录

Ashok Athukuri的更多文章

  • Why I Think Young Software Engineers Lost Their Way

    Why I Think Young Software Engineers Lost Their Way

    Disclaimer: Dear readers, The views, thoughts, and opinions expressed in the text belong solely to the author, and not…

    2 条评论
  • Interviewing Software Developers

    Interviewing Software Developers

    Disclaimer: Dear readers, The views, thoughts, and opinions expressed in the text belong solely to the author, and not…

    3 条评论
  • Code Peer Review (PR), rules and advantages

    Code Peer Review (PR), rules and advantages

    Before discussing about PR review and its advantages, let's talk about how usually developers react on review comments…

社区洞察

其他会员也浏览了