How can I do "opt-in" interfaces with a proxy class in C++? -


i have 5 classes named a b c d e , 2 interfaces i1 i2. using multiple inheritance, might inherit abstract classes implement interfaces:

class : public i1, i2 {};


now, want add more interfaces i3 i4 i5.

having modify 5 class definitions tedious , violates don't repeat yourself programming principle.

how might implement interface proxy class encapsulate polymorphic side of interface instead of multiple inheritance of abstract base classes?

in other words, want have class cast interface class without using inheritance. type operator overload suitable here? or, perhaps using constructor per class good? the goal minimize repetition of code.

i see problem follows:

  • classes a, b, c,... type of documents say, jpg, doc, rtf, xml, pdf,...
  • interfaces i1, i2, i3,... functionalities common documents say, iprint, isavetofile, icompress.

so, every document a, b, c,... needs implement these inferfaces in order provide these functionalities.

if have described requirement correctly then, can use design pattern : visitor.

also, can go in detail if fits requirement.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo