Reputation: 173
I'd like to create object that will be created based on several other objects. I want to use Builder pattern but I have some doubts. I can see that all examples for Builder pattern show that builder has simple methods (e.g. withName(), withSurname(), etc.). Each of these methods assign input parameter to field within builder. Then build() method creates targeted object.
I want to use more complex objects as parameters for these methods. In some of these methods I'm going have more complex logic to create value of field that will be assigned within builder.
Is builder pattern right choice for this? Can builder methods have more complex logic? Should I use another design pattern?
Upvotes: 0
Views: 285
Reputation: 4328
Programming isn't about following patterns to the T. If standard patterns don't fit, make your own. They serve as guides since they exhibit a well tested design.
In this case you can have complex methods if they are necessary, I've seen builders like that before.
Upvotes: 3