What are some best object-oriented design practice

2019-01-30 12:03发布

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.

标签: oop modeling
7条回答
Fickle 薄情
2楼-- · 2019-01-30 12:41

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

查看更多
太酷不给撩
3楼-- · 2019-01-30 12:42

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.

查看更多
乱世女痞
4楼-- · 2019-01-30 12:48

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
查看更多
可以哭但决不认输i
5楼-- · 2019-01-30 12:48

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.

查看更多
一纸荒年 Trace。
6楼-- · 2019-01-30 12:49

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楼-- · 2019-01-30 12:50

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.

查看更多
登录 后发表回答