What is object-oriented design? Contains what? The benefits of it are what? Required to pay what you do? In today's age, ask these questions seem to be foolish, because this year almost every software developer knows how to use some sort of object-oriented programming language. But this question, it is very important, because in my opinion, the vast majority of people in the use of these languages did not know why, but also do not know how the fullest use of them.

The outbreak of the software industry once all the changes, the once one of the two factions have such a wide range of people, they are structured programming and object-oriented programming. All the mainstream of modern programming languages has been their impact on the two fierce. In fact, to not structured and object-oriented programming to write the way procedures are difficult. U.S. mainstream programming languages do not have goto, so that they obey the structured programming the most important prohibitions. Most of our mainstream programming languages are based on the category, but do not support other than in the class-defined functions or variables, and therefore avoid the object-oriented programming in the most likely to fall into the trap.

Using these programming languages prepared by the procedure may appear to be structured or object-oriented, but "looks" are deceiving the people. Today's programming languages often regardless of their sectarian affiliation of the kind of the basic principles of programming languages. I will blog again another chapter to explore the principles of structured programming, in this, I want to talk about object-oriented programming are the basic principles.

In March 1995, I wrote an article and published in comp.object, that is the first time I write OOD (Annotation 1) the principle of the article, after the situation got out of a lot of writing. You can book one of my PPP (Annotation 2) to see them in the object mentor also have a lot of article, including the well-known outline of the article (translated into English soon, please take heed of).

These principles focus on the dependence OOD management, and to downplay aspects of abstraction and modeling. This is not to say in the abstract aspects of OO are not strong enough, or not suitable for building a model of OO. Of course, have a lot of people are using these parts of OO, but to focus on these principles to rely on management.

Management is dependent on each of us must face the problem, whenever we turn on the screen in front of those who tangled with each other also sickening code, we will suffer adverse consequences resulting from reliance on management. Poor management led to rely on the code difficult to change, easily damaged, and can not be reused. In fact, in my book, one PPP had a lot of talk about bad taste different designs, which are dependent on management. On the other hand, if after a healthy reliance on management, the code will be able to maintain flexibility, robustness and reusability. Therefore rely on the management and the relevant principles are much needed to allow programmers to maintain a good software architecture of the cornerstone.

The first five principles are about type design, they are:

SRP, single responsibility principle, a class should have and there is only one reason to change.
OCP, open closed principle, you should not be able to modify the original category will be able to expand a class act.
LSP, Liskov replacement principle, derived class to its base class from the compatibility.
DIP, dependent inversion principle, depend on the abstract rather than implementation.
ISP, interface segregation principle, concerned about their customers as long as the required interface.
Other six are on the package design principles. In this article, refer to a binary file can be released, such as. Jar file, or dll file, rather than Java or C + + package namespace (Annotation 3).

The principle of the first three packets are packets about cohesion, and they will tell us what the put into the package:

REP, the principle of equivalence issued reuse, reuse granularity granularity is released.
CCP, co-closed principle, all types of packets for the same type of changes in the nature of the common should be closed.
CRP, the common principle of reuse, a package of all categories should be common reusable.

Finally the three principles are about the coupling between the package in principle, and discusses the evaluation system in the package structure of the fine or the yardstick.

ADP, the principle of acyclic dependence in package dependency graph does not allow the existence of ring.
SDP, to rely on the principle of stability, stability towards the direction of dependence.
SAP, the stability of abstract principles, including the extent of the abstract should be consistent with their stability.

Annotation:

1, OOD, the full name of Object Oriented Design, that is, object-oriented design.

2, PPP, that is, Uncle Bob's book "Agile Software Development Principles, Patterns and Practice" book, as well as one of their books, because there are "principles, models and practice", that is, Priciples, Patterns and Practices,故常referred to as PPP.

3, namespace original namespace, also translated as Namespace. It is a special kind of scope, it contains a role in the region all the indicators, and is also used to express an identifier, so that will facilitate a series of logically related identifiers an identifier used to organize. On the Java programming language, the namespace is to express through the java package, and all code are vested with a package. From other packets in the code to pass the specified package name to refer to a particular identifier, for example, the java.lang package of String type to pass the form java.lang.String quote. In C + +, the namespace used to avoid naming conflicts, in spite of today's C + + language to make the expansion of the namespace, but the C + + code rarely used this feature.

(Original Link URL: http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod; Robert C. Martin's English blog URL: http://www.butunclebob.com/ArticleS.UncleBob)

About the author: Robert C. Martin is president of Object Mentor, object-oriented design, patterns, UML, agile methodologies and Extreme Programming a senior consultant in the field. Not only is he a Jolt award-winning book, "Agile Software Development: Principles, Patterns and Practice" (Chinese Version) ( "Agile Software Development" (English version of a photocopy of)) the author, or best-selling book Designing Object-Oriented C + + Applications Using the Booch Method the authors. Martin is the Pattern Languages of Program Design 3, and More C + + Gems of the editor-in-chief and co-author James Newkirk of XP in Practice. Him international programmers are well-known spokesman for the General Assembly and C + + Report magazine as the editor of 4 years.