S
spaceboy
Hi !
This is my problem :
I have a big class structure that is something like this :
A contains B contains a vector of C contains D contains a vector of E.
I have an object of A and I want to add an E object in D.
I thought of two options :
1. I call a series of non-const Get function like this (simplified) :
ObjA.GetObjB().GetObjC(indx1).GetObjD().AddEObject(objE);
I don't like this because de Get functions are non-const. These are
provoking side effects and does not encapsulate the modification.
2. Delegate the work down the hierarchy.
A::AddEObject(indx1,ObjE)
{
m_ObjB.AddEObject(ObjE);
}
B::AddEObject(indx1,ObjE)
{
m_ContainerC[indx1].AddEObject(ObjE);
}
C::AddEObject(ObjE)
{
m_ObjD.AddEObject(ObjE);
}
D::AddEObject(ObjE)
{
m_ContainerE.push_back(ObjE);
}
I don't like this either. It seems overkill to me and it will
complexify the maintenance because if D::AddEObject changes, it will
probably mean that all the other AddEObject functions have to change
also.
Do anybody have a 3rd option ?
Thanks !
This is my problem :
I have a big class structure that is something like this :
A contains B contains a vector of C contains D contains a vector of E.
I have an object of A and I want to add an E object in D.
I thought of two options :
1. I call a series of non-const Get function like this (simplified) :
ObjA.GetObjB().GetObjC(indx1).GetObjD().AddEObject(objE);
I don't like this because de Get functions are non-const. These are
provoking side effects and does not encapsulate the modification.
2. Delegate the work down the hierarchy.
A::AddEObject(indx1,ObjE)
{
m_ObjB.AddEObject(ObjE);
}
B::AddEObject(indx1,ObjE)
{
m_ContainerC[indx1].AddEObject(ObjE);
}
C::AddEObject(ObjE)
{
m_ObjD.AddEObject(ObjE);
}
D::AddEObject(ObjE)
{
m_ContainerE.push_back(ObjE);
}
I don't like this either. It seems overkill to me and it will
complexify the maintenance because if D::AddEObject changes, it will
probably mean that all the other AddEObject functions have to change
also.
Do anybody have a 3rd option ?
Thanks !