K
Kaba
Hello
I have a design problem, which I don't seem to have a good solution. By
example:
class B;
class C;
class D
{
public:
// Something
};
class A
{
public:
void clear();
int numberOfBs() const;
private:
map<integer, B*> data_;
};
class B
{
public:
void clear();
int numberOfCs() const;
private:
map<integer, C*> data_;
};
class C
{
public:
void clear();
int numberOfDs() const;
private:
vector<D> data_;
};
The similar interfaces is just a coincidence. As you can see the classes
form a hierarchy. This hierarchy is only finite, that is, I am not after
something like composite pattern.
The class hierarchy is made to partition the D data into chunks which
are more conveniently used in the program.
Now, the data in the Ds is the one that should be modifiable by a user.
The user should not be able to use the non-const functions in B and C
(such as clear). The user should only be able to modify the data in Ds
and use the const functions.
It is like the interfaces should be partitioned into two: one for the
"administrator" and one for the "user". On the other hand, I think
iterators must be used in any case, but how do you satisfy the non-const
requirements?
I hope this description is not too vague.
So how do you traverse all D's in all C's in all B's in all A's with
these requirements?
I have a design problem, which I don't seem to have a good solution. By
example:
class B;
class C;
class D
{
public:
// Something
};
class A
{
public:
void clear();
int numberOfBs() const;
private:
map<integer, B*> data_;
};
class B
{
public:
void clear();
int numberOfCs() const;
private:
map<integer, C*> data_;
};
class C
{
public:
void clear();
int numberOfDs() const;
private:
vector<D> data_;
};
The similar interfaces is just a coincidence. As you can see the classes
form a hierarchy. This hierarchy is only finite, that is, I am not after
something like composite pattern.
The class hierarchy is made to partition the D data into chunks which
are more conveniently used in the program.
Now, the data in the Ds is the one that should be modifiable by a user.
The user should not be able to use the non-const functions in B and C
(such as clear). The user should only be able to modify the data in Ds
and use the const functions.
It is like the interfaces should be partitioned into two: one for the
"administrator" and one for the "user". On the other hand, I think
iterators must be used in any case, but how do you satisfy the non-const
requirements?
I hope this description is not too vague.
So how do you traverse all D's in all C's in all B's in all A's with
these requirements?