DEV Community

Cover image for 7 Valuable tips for Object Oriented Design 😏
Marcos Henrique
Marcos Henrique

Posted on

7 Valuable tips for Object Oriented Design 😏

Whenever you write any code in an object oriented language, follow the list of suggestions below to make your code easier to change with less effort (A.K.A decoupled 🧩)

  1. Separate out parts of code that vary or change from those that remain the same.

  2. Always code to an interface and not against a concrete implementation.

  3. Encapsulate behaviors as much as possible.

  4. Favor composition over inheritance. Inheritance can result in explosion of classes and also sometimes the base class is fitted with new functionality that isn't applicable to some of its derived classes.

  5. Interacting components within a system should be as loosely coupled as possible.

  6. Ideally, class design should inhibit modification and encourage extension.

  7. Using patterns in your day to day work, allows exchanging entire implementation concepts with other developers via shared pattern vocabulary.

I hope these tips have been helpful! 😊

Top comments (2)

Collapse
 
devanghingu profile image
Devang Hingu

your suggestion are great..!! i think there're following things you need to add.
1) Make code more readable.
2) Add comments over codes as you can..!!
3) Follow Prefix adjectives while naming of inheriting classes
4) Always write return at end of function it will destroy memory of all function's local variable and just return on variable.
5) At end of code provide brif summary.

Collapse
 
orimdominic profile image
Orim Dominic Adah

Hmm.. @ Your suggestion 4.. I'm not sure I understand you correctly but what if there's already a default built-in return statement for the programming language at the end of every function?