Software architecture for two similar classes which require different input parameters for the same method
Posted
by
I Like to Code
on Programmers
See other posts from Programmers
or by I Like to Code
Published on 2014-06-05T21:26:42Z
Indexed on
2014/06/05
21:40 UTC
Read the original article
Hit count: 319
architecture
|code-quality
I am writing code to simulate a supply chain.
The supply chain can be simulated in either
an intermediate stocking or a cross-docking configuration.
So, I wrote two simulator objects IstockSimulator and XdockSimulator.
Since the two objects share certain behaviors
(e.g. making shipments, demand arriving),
I wrote an abstract simulator object AbstractSimulator
which is a parent class of the two simulator objects.
The abstract simulator object has a method runSimulation()
which takes an input parameter of class SimulationParameters.
Up till now, the simulation parameters only contains fields
that are common to both simulator objects,
such as randomSeed, simulationStartPeriod and simulationEndPeriod.
However, I now want to include fields that are specific to the type of simulation that is being run,
i.e. an IstockSimulationParameters class for an intermediate stocking simulation,
and a XdockSimulationParameters class for a cross-docking simulation.
My current idea is take the method runSimulation()
out of the AbstractSimulator class,
but to put a runSimulation(IstockSimulationParameters) method
in the IstockSimulator class,
and a runSimulation(XdockSimulationParameters) method
in the IstockSimulator class.
I am worried however, that this approach will lead to code duplication.
What should I do?
© Programmers or respective owner