Welcome!

This weblog was the original abode of Abhijit Nadgouda, now it is moved to iface thoughts. He will appreciate it if you can carry discussions, if you want to, over there. He uses this blog to write specifically about Wordpress or Wordpress.com.

If you are reading any specific post dated on or before 17th August 2006, just replace the domain name with the new one, i.e., replace https://iface.wordpress.com with http://ifacethoughts.net and you will arrive on the same post in the new blog.

Flickr Photos

Affiliations

Traffic

67,704 hits

Common Closure Principle

April 8, 2006 — Abhijit Nadgouda

Common Closure Principle (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. 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.

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.