Class Design with Virtual Methods

How can someone solve such a problem with classes and enter at least the maximum possible code? That's what i

Basic interface for everything

    class IWindow
    {
    public: 
        virtual void Refresh() = 0;
// another 100 virtual methods
// ...
    };

This interface is used inside a library that has no idea about a particular implementation.

Here is a specific implementation version

    class ConcreteWindow : public IWindow
    {
    public:
        void Refresh() override {}
/// the other 100 overridden methods 
    };

Now we have another interface that adds some additional methods, and is also used inside this library.

class IDBDetail : public IWindow
{
public:
    virtual void DoDetail() = 0;

};

and here is the main problem when we create a specific inmplementation for it

class IGDBDetailWrapper : public IDBDetail, public ConcreteWindow
{
public :
    void DoDetail() {}
};

, IGDBDetailWrapper , 100 , , ConcreteWindow, , , , .

/ 100 ConcreteWindow IGDBDetailWrapper, , 10 .

, , 100 ?

+4
6

. , IDBDetail IWindow , :

    class IWindow
    {
    public: 
        virtual void Refresh() = 0;
// another 100 virtual methods
// ...
    };

    class ConcreteWindow : virtual public IWindow
    {
    public:
        void Refresh() override {}
/// the other 100 overridden methods 
    };

class IDBDetail : virtual public IWindow
{
public:
    virtual void DoDetail() = 0;

};

class IGDBDetailWrapper : public IDBDetail, public ConcreteWindow
{
public :
    void DoDetail() {}
};

ConcreteWindow

+2

.

, .

 class IDBDetail : public IWindow { 
  public:
     virtual void DoDetail() = 0;

};

IDBDetail , IDBDetail IWindow. , IDBDetail IWindow. IWindow. , - , .

, .

+4

-, Visual Studio, , , , -:

:

class IDBDetail : public IWindow
{
public:
    virtual void DoDetail() = 0;

};

class IDBDetail
{
public:
    virtual void DoDetail() = 0;

};

, .

, , , ,

class IDBDetailWithConcreteWindow: public IDBDetail{

    IWindow * concreteWindow;
public:
    IDBDetailWithConcreteWindow(IWindow * window){
        concreteWindow = window;
    }

    void Refresh() override{
        concreteWindow->Refresh();
    }
}

, , IDBDetail

IGDBDetailWrapper: public IDBDetailWithConcreteWindow{
public:

   void DoDetail() override { }
}

, (, ), , , IDBDetail.

+3

@bashrc , :

class ConcreteWindow : public virtual IWindow {...}

class IDBDetail : public virtual IWindow {...}

.

+3

, . 100 . , ? IDBDetail , IWindow IGBDDetailWrapper IWindow - .

+2

, :

class IGDBDetailWrapper : public IDBDetail, public ConcreteWindow
{
public:
    virtual void DoDetail() override { /*work here*/ }

    virtual void Refresh() override { ConcreteWindow::Refresh(); }
    //another 100 methods
};

#DEFINE , .

+2
source

All Articles