First, your class ServerCall already has a draw() as a pure virtual function. That's OK.
Second, PlainServerCall derives from ServerCall and implements a draw() for a PlainServerCall. That's OK.
From here on you use PlainServerCall objects by referring to them as ServerCall pointers or references.
ServerCall obj = new PlainServerCall;
then this:
obj->draw();
will call PlainServerCall::draw();
Now your ServerCallDecorator does not add any methods beyond those declared in ServerCall. Until it does, it is a useless class and you don't need it. That is, as of now it does decorate your ServerCall class.
However, let's assume you need to add MethodA() sso you can either
draw() or call MethodA(). You would write code so that:
ServerCallDectorator* dec = new SeverCallDecorator(obj);
where obj is a ServerCall*.
then you can:
1 2
|
dec->draw();
dec->MethodA(); //this is the decorator method
|
aand to make that work, ServerCallDecorator will contain a pointer to a ServerCall object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class ServerCallDecorator
{
private:
ServerCall* theCall;
public:
void draw();
void MethodA();
};
void ServerCallDecorator::draw()
{
theCall->draw();
}
void MethodA()
{
//some logic
}
|
So nowhere in here do you need a cast of any kind.