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

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 55: Line 55:
[1] [http://en.wikipedia.org/wiki/Open/closed_principle The Open-Closed Principle]
[1] [http://en.wikipedia.org/wiki/Open/closed_principle The Open-Closed Principle]


http://agileinaflash.blogspot.com/2009/07/principles-of-package-cohesion.html - Principles of Package Cohesion
[2] [http://agileinaflash.blogspot.com/2009/07/principles-of-package-cohesion.html Principles of Package Cohesion]


http://www2.cs.uh.edu/~svenkat/SoftwareDesign/slides/ObjectOrientedDesignPrinciples.pdf - Object Oriented Design Principles
[3] [http://www2.cs.uh.edu/~svenkat/SoftwareDesign/slides/ObjectOrientedDesignPrinciples.pdf Object Oriented Design Principles]


http://books.google.com/books?id=4pjbgVHzomsC&pg=PA26&lpg=PA26&dq=common+closure+principle&source=bl&ots=snjbB9n0Yf&sig=pHWv9VNcLH-uJGuiyoJjDbPmgnk&hl=en&ei=sif4Som8Dqrg8AaF_-DzCQ&sa=X&oi=book_result&ct=result&resnum=8&ved=0CBoQ6AEwBw#v=onepage&q=Open%20Closed&f=false Java Design: Objects, UML, and Process
[4] [http://books.google.com/books?id=4pjbgVHzomsC&pg=PA26&lpg=PA26&dq=common+closure+principle&source=bl&ots=snjbB9n0Yf&sig=pHWv9VNcLH-uJGuiyoJjDbPmgnk&hl=en&ei=sif4Som8Dqrg8AaF_-DzCQ&sa=X&oi=book_result&ct=result&resnum=8&ved=0CBoQ6AEwBw#v=onepage&q=Open%20Closed&f=false Java Design: Objects, UML, and Process]
http://www.objectmentor.com/resources/articles/granularity.pdf - Granularity


http://ifacethoughts.net/2006/04/08/common-closure-principle/ - Common Closure Principle (ifacethoughts.net)
[5] [http://www.objectmentor.com/resources/articles/granularity.pdf Granularity]


http://missoula.vancouver.wsu.edu/cs320_Fall09/lectures/lecture16.ppt - Object Orient Principles (Washington State University)
[6] [http://ifacethoughts.net/2006/04/08/common-closure-principle/ Common Closure Principle (ifacethoughts.net)]


http://mcs.mines.edu/Courses/csci306/CHAPTERS/Agile/AgileSection4.ppt - Principles of Package Design (Colorado School of Mines)
[7] [http://missoula.vancouver.wsu.edu/cs320_Fall09/lectures/lecture16.ppt Object Orient Principles (Washington State University)]
 
[8] [http://mcs.mines.edu/Courses/csci306/CHAPTERS/Agile/AgileSection4.ppt Principles of Package Design (Colorado School of Mines)]

Revision as of 17:34, 9 November 2009

Common Closure Principle

TOC

Definitions

  • CCP (Common Closure Principle) - “The classes in a package should be closed against the same kinds of change; A change that affects a package affects all the classes in that package.” - R. Martin, 1996.
  • OCP (Open Closed Principle) – "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" – Bertrand Meyer, 1988
  • REP (Reuse-Release Equivalence) – “The granule of reuse is the granule of release. Only components that are released through a tracking system can be efficiently reused.” -R. Martin, 1996


What is CCP?

The Common Closure Principle s defined as “The classes in a package should be closed against the same kinds of change; A change that affects a package affects all the classes in that package.” [R. Martin, 1996]. The real concept here is to ensure that all the classes within a single package are cohesive and decoupled from other classes as much as possible. If you remember this is a typical design principle for classes that for this principle has been extended to entire packages.


The Common Closure Principle is closely associated with the Open Closed Principle. The CCP is tightly connected with the closure portion of OCP. The OCP states that classes should be closed for modification but open for extension. [Granularity] They key idea here is that we should be able to add more functionality to our code without altering the existing functionality in any way. This ensures backwards compatibility for older code systems but allows for future improvements if needed. This is directly tied to expected function signatures and expected function output values for any users that have developed on top of a previously used package.


The Common Closure Principle augments the OCP principle by specifying specific closure practices for a specific package. The principle requires that if code must be modified, possibly for a bug or some other critical reason, then all of the required changes to resolve the issue should be limited to a single package. CCP requires that if any two classes are so closely coupled that they will likely need to be edited in unison in the future that they be part of the same class. The need for this principle is exemplified in the next section.


Why do we need to use CCP?

The Common Closure Principle is targeted at maintainability rather than reusability, which many times is much more important. [Principles of Package Design] We can clarify this concept by a simple example.


 Imagine you are a project manager for a large java software project and after the release of the software you have uncovered a critical bug.  This bug pertained to a specific usage case which was not covered in your testing strategy and covers a wide number of classes.   
 Now imagine that the work on your project has been divided up among smaller teams by the specific packages you’ve implemented.  Which would you rather have, a single team able to handle the entire code alteration ensuring that they can intracommunicate and insure that all the required changes are cohesive in the classes?   Or would you rather distribute the work and require a large amount of intercommunication between teams to ensure cohesion?  


The obvious answer from the example above is to allow a single team to handle the resolution of the problem. This will simplify testing and integration of the next release by preventing separate teams from introducing separate bugs into the code and preventing the need for each of the packages to be revalidated independently. Also this will correlate the resolution of the bug to a single package change which can make it easier to distribute the patch to clients.


Conflicting Principles

The CCP principle can sometimes lead to confusion when also considering the Reuse-Release Equivalence Principle. This principle tells use to combine code into packages based on user convenience and usage patterns. Essentially if classes are typically used in unison then why not package them together?

Many users find it hard to find a balance between obeying both REP and CCP. The trade off here is user convenience and maintainability. Program designers need to be careful to separate new and moderately unstable code from older and highly stable code in packages when considering how to package code for user convenience. Maintainability and User Convenience are both very important and a good balance for both need to be discovered when packaging code.


Examples

Links

[1] The Open-Closed Principle

[2] Principles of Package Cohesion

[3] Object Oriented Design Principles

[4] Java Design: Objects, UML, and Process

[5] Granularity

[6] Common Closure Principle (ifacethoughts.net)

[7] Object Orient Principles (Washington State University)

[8] Principles of Package Design (Colorado School of Mines)