Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some best object-oriented design practices? [closed]

Tags:

I didn't find any question that would be this general.

Please post whatever you find to be a useful rule for oject-oriented design.

like image 689
Vojto Avatar asked Apr 28 '11 06:04

Vojto


People also ask

What are the 4 main object-oriented principles?

Now, there are four fundamental concepts of Object-oriented programming – Inheritance, Encapsulation, Polymorphism, and Data abstraction.

What are OOP practices?

Object-oriented programming aims to implement real-world entities like inheritance, abstraction, polymorphism, and encapsulation in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.

What are the 5 OOP principles?

The SOLID principles of OOP are: Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle (LSP), Interface Segregation Principle (ISP), and Dependency Inversion Principle (DIP).

What is a good OO design?

Gamma's second principle of good OO design is to: Favor object composition over class inheritance. Systems that follow this rule have fewer classes and more objects. Their power is in the ways that the objects can interact with each other. It would be important to have good dynamic models.


3 Answers

There are many, many OOD practices (Google it!) if you had to pick over others I would go with SOLID an acronym for;

  1. Single Responsibility Principal
  2. Open/closed principle
  3. Liskov substitution principle
  4. Interface segregation principle
  5. Dependency inversion principle
like image 120
Pete Stensønes Avatar answered Nov 19 '22 11:11

Pete Stensønes


I have recommended the Head First Design Patterns book many times.

It gives you a good intro to the GoF Design Patterns (a more advanced book that you also should read), but also a good intro to sound OOP design principles.

enter image description here

like image 39
Jørn E. Angeltveit Avatar answered Nov 19 '22 12:11

Jørn E. Angeltveit


Few other principles are

  1. "Hollywood principle" which means lower layers should not depend on higher layers.
  2. "Favor composition over inheritance" - composition allows changing/adding behavior at runtime and is more maintainable
  3. "Program to an interface, not to the implementation" - always use abstraction as a way of referencing instead of direct coupling to the concrete class

I suggest you to look into "Head first - OOAD" as well..

like image 26
Sandeep G B Avatar answered Nov 19 '22 13:11

Sandeep G B