C++: object composition
In my application I require 2 objects of class State:
aState1 is updated by an iterative process
aState2 is updated by changes to aState1 and is used to configure and
drive a large external model.
aState1 is needed so that the same model can be driven for a different
configuration - they are related but are not interchangeable.
External to this model several clients need access to data contained in
either aState1 or aState2, so I have an interface with derived classes:
class stateInterface
{
public:
void Get_X() = 0;
...
};
class implementState1 : public stateInterface // interact with `aState1`
{
public:
void Get_X(); // from aState1
bool Update_State() { return
m_slave->Update_State(); }
private:
implementState2* m_slave;
...
};
class implementState2 : public stateInterface // interact with `aState2`
{
public:
void Get_X(); // from aState2
bool Update_State();
private:
implementState1* m_master;
...
};
My question is, should implementState1 and implementState2 contain aState1
and aState2, respectively, or only use them? Or should the State be
contained in stateInterface? Considerations are that State objects contain
a lot of data and the model into which they are passed is highly
multithreaded. They are only to be modified in the ways described above,
and they don't need to outlive the implementStateX objects. Thanks in
advance.
No comments:
Post a Comment