What are some best object-oriented design practice

2019-01-30 12:37发布

问题:

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.

回答1:

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


回答2:

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.



回答3:

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..



回答4:

Good summary of OOD principles can be found here: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

The author is Robert C. Martin (also known as Uncle Bob), programming specialist with more than 40 years of experience in programming.

Articles are taken from his book "Clean Code" which IMHO is a really good material for OOP design principles.



回答5:

Read other people's code and try to design class diagrams.
It will give you an idea of how other people think through problem solving.
That helps me a lot. Especially frameworks.



回答6:

The best of OOP nothing, any approach that's fit for your project is best. But it is important what are OOP practices before choosing any/many from them for your project.

1: APIE: Abstraction, Polymorphism, Inheritance, Encapsulation.

2: SOLID Principle.

3: OO analysis and design.

4: Design patterns.

5: Code refactoring.

6: Effective Java.



回答7:

In my view,I think if you want to learn about Object Oriented design you should try to play with Smalltalk language since it is the language which started Object Oriented programming.

We have an alternative now called Squeak which is open source.SOLID as out fellow mate mentioned also gives you a great idea about OOPS.

All the best on your OOPS journey.

You can check out Squeak on Squeak on Web.



标签: oop modeling