vendredi 16 février 2018

Factory Pattern with Multiple Inheritance

In this problem I have three pure virtual classes, let's name them A, B, C. Each of them provides a different set of functionality. I have another pure virtual class that I will call CommonInterface that does not introduce any new functionality but inherits A, B, and C to make them reachable through a single interface as below:

class CommonInterface : public virtual A, public virtual B, public virtual C

These interfaces are defined by a standard document and are not subject to change. They are defined as a factory design pattern, such that, anyone can implement the functionality of CommonInterface according to their needs.

My role is to provide a built-in implementation to this CommonInterface, so that people can use my implementation in case the built-in implementation of the interface is good enough for them. I want to design the built-in implementation well but I am not very sure how to apply the factory pattern to multiple inheritance cases. My current implementation implements each base interface as

class BuiltinA : public virtual A
class BuiltinB : public virtual B
class BuiltinC : public virtual C

and then implements common interface as given below:

class BuiltinImplementation : public virtual CommonInterface, public BuiltinA, public BuiltinB, public BuiltinC

Is this a good or bad design? If it is a bad design, how can I improve it? Also is there any patterns I can apply to this case? Any expert opinion is welcome. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire