Pattern for this? Or something?

N

notme

Supposing I have two classes:

class UIControl1 : public BaseControl1 {}

class UIControl2 : public BaseControl2 {}

where both base classes are not related between them.
Then I'd like to -depending the user preference- use one of
those controls. That is, I have to do this at runtime, depending
on some flag set by the user of the program. Is there any way
to relate these two classes? If they derived from the same (or
related) base, then I would easily use that base class pointer,
without worrying which class I'm using. But in this case, what
can I do?

TIA
 
D

David White

notme said:
Supposing I have two classes:

class UIControl1 : public BaseControl1 {}

class UIControl2 : public BaseControl2 {}

where both base classes are not related between them.
Then I'd like to -depending the user preference- use one of
those controls. That is, I have to do this at runtime, depending
on some flag set by the user of the program. Is there any way
to relate these two classes? If they derived from the same (or
related) base, then I would easily use that base class pointer,
without worrying which class I'm using. But in this case, what
can I do?

You can write your own proxy classes, e.g.,
class UIControl1Proxy : public BaseControlProxy
{
UIControl1 mUIControl1;
...
};

class UIControl2Proxy : public BaseControlProxy
{
UIControl2 mUIControl2;
...
};

Add a polymorphic public interface to BaseControlProxy and override it in
each of the derived classes, and at runtime choose which derived class to
use.

DW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top