Creational patterns hide how instance of classes are constructed. Thereby enabling more independence and increasing flexibility in a system. In this series, we try to look at the most common creational patterns and their unique features.
To demonstrate the implementation of the creational patterns, we will use, as an example, what we have named as “The Design-pattern Cafe”. The Design-pattern Cafe is a fictitious Cafe based in Ethiopia. For each pattern,
we have devised a problem-scenario that could potentially be solved with the pattern.
All of the sample code used as examples can be found on GitHub at:
dp-team / creationaldesignpatterns
Demo code on creational design patterns
Creational Design Patterns Demo
This repo contains demo codes for creational design patterns using, as an example a fictitious virtual cafe named "the design-pattern cafe".
We came up with this example to better illustrate the design patterns For each pattern, we have devised a problem-scenario that could potentially be solved with the pattern.
Factory Method Pattern
Scenario: The design-pattern cafe is growing popular and the owners decided to open a new branch in France But there is a problem, all the menus are in English and the French could not understand it. There is also a confusion in the currency. The French use the Euro but the system displays price in Ethiopian Birr.
Solution: We can solve this problem by first creating an abstract Menu class, and then creating concrete classes that extend this abstract class to make a French and other language versions of the menu. We then create…
Top comments (0)