Which design patterns should I use?

Viewed 43

I want to create UML class diagram. My problem is:

Suppose you are creating a furniture store simulator. You have to deal with different types of furniture such as chairs, sofas, tables, cabinets from different styles such as classic, modern, retro and country. While creating individual furniture objects with the simulator, each furniture object must be able to be used together with other furniture objects that fit the same furniture style. In the simulator, at most one object should be able to function to create individual furniture objects from each furniture style. New furniture styles and furniture types should also be added in the future.

Which design patterns should I use together? Can you share a sample code or class diagram?

1 Answers

Abstract Factory

The first thing the Abstract Factory pattern suggests is to explicitly declare interfaces for each distinct product of the product family (e.g., chairs, sofas, tables and cabinets). Then you can make all variants of products follow those interfaces. For example, all chair variants can implement the Chair interface; all tables table variants can implement the Tables interface, and so on.

Now, how about the style of the products? For each style of a product family, we create a separate factory class based on the AbstractFactory interface. A factory is a class that returns products of a particular kind. For example, the ModernFurnitureFactory can only create ModernChair, ModernTable and ModernCabinets objects.

Related