Hello there,
I am having trouble coming up with a good design for a group of classes and was hoping that someone could give me some guidance on best practices. I have kept the classes and member functions generic to make the problem simpler.
Essentially, I have three classes (lets call them A, B, and C) as follows:
class A
{
public:
...
int GetX( void ) const { return x; };
int GetY( void ) const { return y; };
private:
B b; // NOTE: A "has-a" B
int x;
int y;
};
class B
{
public:
...
void SetZ( int value ) { z = value };
private:
int z;
C c; // NOTE: B "has-a" C
};
class C
{
public:
...
void DoSomething(int x, int y){ ... };
void DoSomethingElse( int z ){ ... };
};
My problem is as follows:
- Class A uses its member variables "x" and "y" a lot internally.
- Class B uses its member variable "z" a lot internally.
- Class B needs to call C::DoSomething(), but C::DoSomething() needs the values of X and Y in class A passed in as arguments.
- C::DoSomethingElse() is called from say another class (e.g. D), but it needs to invoke SetZ() in class B!.
As you can see, it is a bit of a mess as all the classes need information from one another!. Are there any design patterns I can use?. Any ideas would be much appreciated ....