CSC/ECE 517 Fall 2009/wiki3 3 cp: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 95: Line 95:


'''Stable Dependencies Principle SDP:''' this principle recommends that the dependee must be more stable than the depender, they usually follow the direction of stability.
'''Stable Dependencies Principle SDP:''' this principle recommends that the dependee must be more stable than the depender, they usually follow the direction of stability.
Most of the definitions were inspired on the web page [http://ootips.org/ood-principles.html What Makes A Good Object-Oriented Design?] written by Tim Ottinger

Revision as of 02:50, 19 November 2009

Common Closure Principle

In simple words the Common Closure Principle refers to classes that change topether, belong together, this is a very simple definition taken from the book Java Design: Objects, UML and Process written by Kirk Knoernschild.

A more explained definition of Common Closure Principle is given by Robert Martin, which states that:

      THE CLASSES IN A PACKAGE SHOULD BE CLOSED TOGETHER AGAINTS THE SAME 
      KINDS OF CHANGES. A CHANGE THAT AFFECTS A PACKAGE AFFECTS ALL THE 
      CLASSES WITHIN THAT PACKAGE. 
      

See Granularity PDF Article written by Robert Martin for more details

In other words, what affects one affects all, a broader and detailed explanations are given in this wikiwork.

Introduction and Objective

There are several web pages that explain in few words what is Common Closure Principle, but they fall short by just giving definitions and very few examples.

Therefore the objective of the wiki work is to dedicate a deeper investigation on this topic with examples.

A deep definition of Common Closure Principle CCP

CCP is another package design principle which tries to look at maintainability rather than usability. The principle advises on which classes should be packaged together from a change and distribution point of view

Even though most of the class design principles advocate loose coupling between classes, so that they can change without affecting the other, dependencies between classes cannot be avoided. CCP tries to look at classes that are dependent on each other from a code change perspective. Even though Open-Closed Principle (OCP) recomments full closure to code change, it is not always possible. Sometimes some of the class design principles are violated consciously to improve performance, just like denormalization in databases. However this violation should be a conscious decision and the product should be ready for changes because of it.

To enable easy distribution/update/release and maintainability, it is advisable to localise the changes to a package. Only the modified package can then be released, making the update easier. Even if the changes cannot be restricted to a single package, minimal packages should be required to be changed. To get an idea of the code change dependencies, we can take guidance from Law Of Demeter (LOD) principle, which tries to point out classes which know each other’s structures.

One issue is when dependencies between packages in a design should be in the direction of stability of the packages, in other words a package should only depend upon packages that are more stable than it is.

Some volatility is necessary if the design is to be maintained. This is achieved by using the Common Closure Principle, in this way we design packages to be volatile and we expect them to change. Any package that we expect to be volatile should not be depended upon by a package that is difficult to change.

Some things we don’t want to change. For example architectural decisions should be stable and not at all volatile. Therefore classes that encapsulate the high level design should be stable.

Regarding Granularity

More important than reusability, is maintainability.

If the code in an application must change, where would you like those changes to occur: all in one package, or distributed through many packages? It seems clear that we would rather see the changes focused into a single package rather than have to dig through a whole bunch of packages and change them all. That way we need only release the one changed package. Other packages that don’t depend upon the changed package do not need to be revalidated or rereleased.

The CCP is an attempt to gather together in one place all the classes that are likely to change for the same reasons. If two classes are so tightly bound, either physically or conceptually, such that they almost always change together; then they belong in the same package. This minimizes the workload related to releasing, revalidating, and redistributing the software.

This principles is closely associated with the Open Closed Principle (OCP). For it is “closure” in the OCP sense of the word that this principle is dealing with. The OCP states that classes should be closed for modification but open for extension. As we learned in the article that described the OCP, 100% closure is not attainable. Closure must be strategic. We design our systems such that the are closed to the most likely kinds of changes that we foresee.

The CCP amplifies this by grouping together classes which cannot be closed against certain types of changes into the same packages. Thus, when a change in requirements comes along; that change has a good chance of being restricted to a minimal number of packages.

What are the advantages and disadvantages?

Goal: limit the dispersion of changes among released packages u changes must affect the smallest number of released packages

Classes within a package must be cohesive

Given a particular kind of change, either all classes or no class in a component needs to be modified.

Group classes with similar closure together, package closed for anticipated changes.

Confines changes to a few packages.

Reduces package release frequency.

Reduces work for the programmer and makes easier to maintain it.

Going from OCP to CCP, in this case the classes should be open for extension, but closed for modification, this is an ideal scenario, instead classes will be designed for likely kinds of changes

Cohesion of closure in a package should be closed to the same kinds of changes and they will be confined within few packages

Reduces frequency of release of packages

Reading Recommendations

Reference Books

External Links

Bob Martin's

Appendix

Open/Closed Principle OCP: Entities like classes or modules need to be open to extend them, at the same time they need to be closed for modification.

Liskov Substitution Principle LSP: Any base class function must not be confused when a derived class is substituted for the base class. it is also known as "Design by Contract" principle in Robert Martin

Dependency Inversion Principle DIP: The details must be based on abstractions and not in the other way aroud, abstractions based on details.

Interface Segregation Principle ISP: Some interfaces can be grouped in member functions, in this way the clients use one group of member functions, and other clients use the other groups according to their porpouse. the clients use specific interfaces instead of the general interface.

Reuse/Release Equivalency Principle REP: Reuse and Release are almost the same in the sense that only Released components through a tracking system are Reused components.

Common Closure Principle CCP: If the changes are of the same kind then they shloud be closed together, in other words, classes that change together, belong together and form groups

Common Reuse Principle CRP: It refers to the clases that are reused together, if they are not then they should not be grouped. The effect of applying Common Reuse is that if you reuse one you reuse all of them.

Acyclic Dependencies Principle ADP: The structure for released components must never form a dependency cycle.

Stable Dependencies Principle SDP: this principle recommends that the dependee must be more stable than the depender, they usually follow the direction of stability.

Most of the definitions were inspired on the web page What Makes A Good Object-Oriented Design? written by Tim Ottinger