S
slitvinov
Hi,
I think I cannot make I good design decision in the following
situation
I have a class Particle. And a derived class PolymerParticle
Now I would like to create an object to represent the interaction
between two particles. For different pairs it should be a different
kind of interaction.
for Particle - Particle --- Interaction
for Particle - PolymerParticle --- PolymerHydroInteraction
for PolymerParticle - PolymerParticle -- PolymerPolymerInteraction
PolymerHydroInteraction and PolymerPolymerInteraction are derived from
the Interaction class.
At some point I have two pointers Particle*. And my current solution is
to create a function
Interaction* CreateInteraction(Particle*, Particle*)
This function uses dynamic_cast to convert Particle pointers and then
creates and returns the correct type of interaction.
Is there a better way to do the same thing? Maybe I am missing
something about C++.
I think I cannot make I good design decision in the following
situation
I have a class Particle. And a derived class PolymerParticle
Now I would like to create an object to represent the interaction
between two particles. For different pairs it should be a different
kind of interaction.
for Particle - Particle --- Interaction
for Particle - PolymerParticle --- PolymerHydroInteraction
for PolymerParticle - PolymerParticle -- PolymerPolymerInteraction
PolymerHydroInteraction and PolymerPolymerInteraction are derived from
the Interaction class.
At some point I have two pointers Particle*. And my current solution is
to create a function
Interaction* CreateInteraction(Particle*, Particle*)
This function uses dynamic_cast to convert Particle pointers and then
creates and returns the correct type of interaction.
Is there a better way to do the same thing? Maybe I am missing
something about C++.