I'm a little new to the more complex C ++ functions. Yesterday I posted the following question, and I learned about virtual inheritance and the scary diamond of death.
Inheriting both an interface and a C ++ implementation
I also learned through other links that multiple inheritance is usually a sign of bad code and that the same results can usually be achieved better without using IM. The question is ... I don’t know what is the best, one-way approach for the next problem.
I want to define an interface for two types of digital points. Digital input point and digital output point. The interface should be thin, only for access to information. Of course, the vast majority of properties are common to both types of digital points. Therefore, for me this is a clear case of Inheritance, not composition.
My interface definitions look something like this:
class IDigitalPoint
{
public:
virtual void CommonDigitalMethod1() = 0;
};
class IDigitalInputPoint : virtual IDigitalPoint
{
public:
virtual void DigitialInputMethod1() = 0;
};
class IDigitalOutputPoint : virtual IDigitalPoint
{
public:
virtual void DigitialOutputMethod1() = 0;
};
And my implementations look like this:
class DigitalPoint : virtual public IDigitalPoint
{
public:
void CommonDigitalMethod1();
void ExtraCommonDigitalMethod2();
}
class DigitalInputPoint : public DigitalPoint, public IDigitalInputPoint
{
public:
void DigitialInputMethod1();
void ExtraDigitialInputMethod2();
}
class DigitalOutputPoint : public DigitalPoint, public IDigitalOutputPoint
{
public:
void DigitialOutputMethod1();
void ExtraDigitialOutputMethod2();
}
So how could I reformat this structure to avoid MI?
Thanks in advance for your help.
source
share