Link to home
Start Free TrialLog in
Avatar of Eindoofus
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->TruckImplFactory->CargoTruckImpl->MovementImplFactory-> CargoTruckMovmentImpl

FuelTruck->TruckImplFactory->FuelTruckImpl->MovementImplFactory-> 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.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Eindoofus
Eindoofus

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-exchange.com/Programming/Misc/Q_27390742.html#a36949352
ASKER CERTIFIED SOLUTION
Avatar of gordon_vt02
gordon_vt02

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial