Skip to content

Instantly share code, notes, and snippets.

@kenjihiranabe
Last active Aug 29, 2015
Embed
What would you like to do?
オブジェクト指向の法則集 ref: http://qiita.com/kenjihiranabe/items/9eddc70e279861992274
Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.
A method "M" of an object "O" should invoke only the the methods of the following kinds of objects:
1. itself
2. its parameters
3. any objects it creates/instantiates
4. its direct component objects
A. High level modules should not depend upon low level modules. Both should depend upon abstractions.
B. Abstractions should not depend upon details. Details should depend upon abstractions.
Clients should not be forced to depend upon interfaces that they do not use.
The granule of reuse is the granule of release. Only components that are released through a tracking system can be effectively reused. This granule is the package.
The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all.
The classes in a package should be closed together against the same kinds of changes. a change that affects a package affects all the classes in that package.
The dependency structure between packages must be a directed acyclic graph (DAG). That is, there must be no cycles in the dependency structure.
The dependencies between packages in a design should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable that it is.
Packages that are maximally stable should be maximally abstract. Instable packages should be concrete. The abstraction of a package should be in proportion to its stability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment