Why is this design flawed?
If we specify a color either at construction time or through the setColor call, the object copies the pointer to the external Color class to its internal pointer.
So our objects are in fact pointing to other objects outside their scope.
We (the user) might choose to delete the Color object, leaving the internal pointer pointing to an invalid location, or we might change the Color object directly and so change the cube’s or cylinder’s properties behind its back.
Occasionally this is a desired functionality, but there are better and safer implementations for that.
On our way to a better solution, we will now introduce several new concepts:
- overloaded functions and operators
We will see the concept of a client-server contract which is important for distributed computing.