menu

秋梦无痕

一场秋雨无梦痕,春夜清风冻煞人。冬来冷水寒似铁,夏至京北蟑满城。

Avatar

Design Principles

From: 《Design Principles and Design Patterns》
By: Robert C. Martin www.objectmentor.com

Additional info comes from web pages.
========================================
Principles of Object Oriented Class Design:
========
The Open Closed Principle (OCP): A module should be open for extension but closed for modification.

The Liskov Substitution Principle (LSP): Subclasses should be substitutable for their base classes.
i.e: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.

The Dependency Inversion Principle (DIP): Depend upon Abstractions. Do not depend upon concretions.
i.e: High-level modules should not depend upon low-level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.

The Interface Segregation Principle (ISP): Many client specific interfaces are better than one general purpose interface.

The Law of Demeter(LoD): A supplier object to a method M is an object to which a message is sent in M.
i.e: Only talk to your immediate friends.
i.e: Don't talk to strangers.
i.e: An object O in response to a message M should send messages only to the following preferred supplier objects:
1. O itself,
2. objects sent as arguments of message M,
3. objects O creates as part of its reaction to message M,
4. objects which are directly accessible instance variables of O,
5. objects which provide global services to O.

The Composite/Aggregation Reuse Principle(CARP): Favor composition over inheritance to achieve polymorphism.

Principles of Package Architecture:
========
The Reuse/Release Equivalency Principle (REP): The granule of reuse is the granule of release.

The Common Closure Principle (CCP): Classes that change together, belong together.

The Common Reuse Principle (CRP): Classes that aren’t reused together should not be grouped together.
i.e: The classes in a package are reused together. If one of the classes in a package is reused, all the classes in that package are reused.

Principles of Package Coupling:
=========
The Acyclic Dependencies Principle (ADP): The dependencies betwen packages must not form cycles.

The Stable Dependencies Principle (SDP): Depend in the direction of stability.
i.e: Less stable packages should depend on more stable packages.

The Stable Abstractions Principle (SAP): Stable packages should be abstract packages.
i.e: The instable packages should contain the concrete implementations.

评论已关闭