CCP

CCP Explained In Pictures (Part 2)

We’ll continue yesterday’s exploration of the Common Closure Principle (CCP) in pictures. The CCP is one of the three Cohesion Component Principles that help us programmers group classes and modules into deployable components.

Congratulations to Steve Buys, who provided the first correct answer to yesterday’s question on how to partition the presentation logic classes into rational components! Thank you to everyone who participated and sent in their answers!

If you missed out on the component partitioning problem from yesterday, you can read about it here

Let’s find out the solution.

Our small desktop application needed a web interface as well. Below is a depiction of the system classes and the components as we had them. Classes A & B belong to the web interface, while classes C, D, E & F provide the desktop app behaviour. 

The desktop and web interfaces are built using different technologies and frameworks. The classes belonging to web and desktop apps will diverge and develop along separate paths. If we follow the CCP, we should separate these into different components. OK, how could we achieve this?

How about we create a separate component only for the web app?

 

Well, that arrangement of classes would be suboptimal. Why? Because the web app component would depend on the desktop/business logic component. Therefore this web component could depend on desktop presentation logic! That seems wrong. Similarly, extracting merely the desktop logic into a component, as shown below, would be affected by the same predicament.

OK, what is the solution? Desktop and web presentation logic involve different technologies and will evolve in different directions. Therefore the classes for each should be grouped into separate components:

That concludes our journey into the CCP. I hope you’ve enjoyed it.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply