Common closure principle

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
Line 2: Line 2:
 
:''The classes in a package should be closed together against the same kind of changes. A change that affects a package affects all the classes in that package.'' [http://ifacethoughts.net/2006/04/08/common-closure-principle/ ifacethoughts.net]
 
:''The classes in a package should be closed together against the same kind of changes. A change that affects a package affects all the classes in that package.'' [http://ifacethoughts.net/2006/04/08/common-closure-principle/ ifacethoughts.net]
  
 
This means: "The classes that tend to be reused together belong in the same package",[[Robert Cecil Martin 1996b]]
 
  
 
Although most design principles advocate loose-coupling between classes, sometimes it is unavoidable. This may be because of a consequence of the design, or a deliberate action such as performance tuning. In these cases, these classes should be packaged together, so a change only effects the classes in that package. This makes updating the system easier, as only the new package needs to be distributed. The [[Law of Demeter]] is a useful way to find out which classes know other's structure, and thus should probably be in the same package.
 
Although most design principles advocate loose-coupling between classes, sometimes it is unavoidable. This may be because of a consequence of the design, or a deliberate action such as performance tuning. In these cases, these classes should be packaged together, so a change only effects the classes in that package. This makes updating the system easier, as only the new package needs to be distributed. The [[Law of Demeter]] is a useful way to find out which classes know other's structure, and thus should probably be in the same package.

Revision as of 08:51, 6 October 2008

The Common closure principle is concerned with program maintainability. It states:

The classes in a package should be closed together against the same kind of changes. A change that affects a package affects all the classes in that package. ifacethoughts.net


Although most design principles advocate loose-coupling between classes, sometimes it is unavoidable. This may be because of a consequence of the design, or a deliberate action such as performance tuning. In these cases, these classes should be packaged together, so a change only effects the classes in that package. This makes updating the system easier, as only the new package needs to be distributed. The Law of Demeter is a useful way to find out which classes know other's structure, and thus should probably be in the same package.

See also

Personal tools