Reputation: 41
Good afternoon,
For an excersise I have to design an app that creates shapes like a rectangle. To draw a rectangle you should call a display() function with four parameters: x, y, w, h (bottom left coordinates, width and height). Now a new client wants to call the display method with top-left coordinates and bottom right coordinates.
I am trying to decide which design pattern suits this task best. Factory or builder design pattern?
Thanks in advance.
Upvotes: 0
Views: 157
Reputation: 8215
The Factory pattern can be used for creating any kind of object but it is not specific to your requirement.
The Builder pattern only makes sense for complex objects which you don't have here.
What comes to my mind here is the Strategy pattern. You have two drawing strategies that can be applied to the rectangle.
Upvotes: 1
Reputation: 3091
Actually, this problem doesn't need any of these patterns. You can achieve this by method overloading easily. Just define two display methods with different number of parameters.
If you want to practice design patterns, you should find more suitable problems for these patterns.
Upvotes: 0