Eindoofus
asked on
Need suggestions for my design. Am I using Factory and Impl classes properly?
In my 2d simulator I have a CargoTruckImpl, which is spawned from the TruckImplFactory (that was called by the CargoTruck class), asking the MovementImplFactory for it's CargoTruckMovementImpl. And then I also have a FuelTruckImpl doing the same thing by calling the MovementImplFactory for it's own FuelTruckMovementImpl. So basically I'm doing the following:
CargoTruck->TruckImplFacto ry->CargoT ruckImpl-> MovementIm plFactory- > CargoTruckMovmentImpl
FuelTruck->TruckImplFactor y->FuelTru ckImpl->Mo vementImpl Factory-> FuelTruckMovmentImpl
Is this a good or bad design? Am I violating the Seperation Principle or the Open-Closed Principle by doing this? Is there a better way of doing this?
--
I would prefer a thoughtful conceptual answer. No quick posting or links please.
CargoTruck->TruckImplFacto
FuelTruck->TruckImplFactor
Is this a good or bad design? Am I violating the Seperation Principle or the Open-Closed Principle by doing this? Is there a better way of doing this?
--
I would prefer a thoughtful conceptual answer. No quick posting or links please.
There is not often a reference in an implementation class to its factory. I'd be interested to be shown examples ofwhere that's not the case though
ASKER
I posted that wrong. I meant that CargoTruck is referencing CargoTruckImpl, which both implement an interface called Truck. And that TruckImplFactory is just making the decision to return CargoTuckImpl to CargoTruck when called. Which brings me back to my other questions of how can I make the TruckImplFactory choose between CargoTruckImpl and FuelTruckImpl based on whether CargoTruck or FuelTruck call it?:
http://www.experts-exchang e.com/Prog ramming/Mi sc/Q_27390 742.html#a 36949352
http://www.experts-exchang
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.