I am trying to design a system. I thought that bridge pattern would be helpful but maybe I am going mad and there is a better option. I am not a software pattern expert.
I need to draw a shape depending on the shape type, the colour and the wall where is going to be painted on.
There are two shapes: Rectangle and Circle There are two colours: Red and Blue There are two walls: Wood wall and Concrete wall
First naive attemp would be:
----Shape---
/ \
Rectangle Circle
/ \
BlueRectangleWoodWall BlueCircleWoodWall
BlueRectangleConcreteWall BlueCircleConcreteWall
RedRectangleWoodWall BlueCircleWoodWall
RedRectangleConcreteWall BlueCircleConcreteWall
In total 11 classes! I think that's not a good idea. If I didn't have to worry about the type of wall, I would do a bridge:
----Shape--- Color
/ \ / \
Rectangle(Color) Circle(Color) Blue Red
But I need to add the wall variation so I thought doing something like a "double bridge"?
----Shape--- Color
/ \ / \
Rectangle(Color) Circle(Color) Blue(Wall) Red(Wall)
Wall
/ \
ConcreteWall WoodWall
Is this a good idea? I am not a software pattern expert. That's why I am asking for help. In this case I only decrease from 11 classes to 9. Thank you!
Aucun commentaire:
Enregistrer un commentaire