What are some best object-oriented design practices? [closed]
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
开发者_如何学编程Improve this questionI didn't find any question that would be this general.
Please post whatever you find to be a useful rule for oject-oriented design.
There are many, many OOD practices (Google it!) if you had to pick over others I would go with SOLID an acronym for;
- Single Responsibility Principal
- Open/closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle
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.
Few other principles are
- "Hollywood principle" which means lower layers should not depend on higher layers.
- "Favor composition over inheritance" - composition allows changing/adding behavior at runtime and is more maintainable
- "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..
Good summary of OOD principles can be found here: https://web.archive.org/web/20190714115656/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.
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.
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.
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.
精彩评论