Search code examples
design-patternsdesign-principles

Design Improvement


Suppose that we have a UI with a selectOneMenu, which contains two items basic and customized. Let the class DocumentController be responsible for generating PDF documents for the chosen type (basic or customized).

It is clear that an extention of the UI( for instance new item) leads to a modification of the class DocumentController. Hence the class DocumentController violates the Open Closed principle, that implies that it also violates the Single Responsibility Principle

My approach for solving this problem based on the Chain of Responsibility Design Pattern, so I created for each item of selectOneMenu a separate class. Now the application is open for extensions but closed for modifications ans each class is responsible exactly for one thing.

Now my question is how to manage disjoint and commen data of the new classes. Is Chain of Responsibility Design Pattern suitable for this problem?

Thank you for any suggests


Solution

  • ...be responsible for generating PDF documents...

    What about thinking about this a little differently and allowing the controller to delegate to an abstract factory, which has basic and customised implementations? This way you're safely in SOLID territory.