Dear monks,
I'm designing a system that should use the builder pattern (I think...) to build a complex product, all orchestrated by one Director class. The real problem is a bioinformatics one and difficult to explain to non-biologists, but this here is essentially the same in a more "real-world" example.
Let's say we have a class representing a buyer. A buyer requests a new vehicle and the VehicleDealer then gets a VehicleBuilder to build the vehicle, which could be a Car or a Motorbike, so the concrete builder class will be a CarBuilder or a MotorbikeBuilder:
So far so good but my problem now is that a vehicle has lots of parameters, let's say in this case all the customizable details like outside/inside colours and materials etc.################ ################# # VehicleBuyer # --> # VehicleDealer # ################ ################# | V ################## # VehicleBuilder # ################## | ---------------+----------- V V ############### #################### # CarBuilder # # MotorbikeBuilder # ############### #################### | | V V ######## ############# # Car # # Motorbike # ######## #############
My problem now is that the VehicleDealer and the VehicleBuilder and of course the concrete Product classes (Car and Motorbike) all need to have attributes for all of the parameters I can pass around.
At first I implemented these attributes (I'm using Moose by the way) in each of those classes but that was a lot of duplication, so now I moved them all into Moose roles and consume the roles.
Now I have much shorter code for those classes but I can see problems maintaining this because the attributes that any one of those objects has are spread across several roles and in the end I still have to document each class, so basically I'll end up duplicating, if not the code, then at least the documentation for all those parameters.
My question: how do others deal with a problem like this? Maybe I'm missing a design pattern that would help me out here? Maybe ther just isn't a better way of doing this - just thought I'd ask...
Thanks for your help!!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |