jeudi 16 novembre 2017

splitting interfaces between classes

I create a component where I need to implement 3 interfaces:

Interface A:

virtual void SetSomeInfo(Info) = 0;

Interface B:

virtual void SomeInfoChanged(Info) = 0;

Interface C:

virtual SomeData GetSomeDataX() = 0;
virtual SomeData GetSomeDataY() = 0;
virtual SomeData GetSomeDataZ() = 0;

Clients A and B use interfaces A and B to send some informations. Based on those informations a component builds some data structure. Client C using interface C gets data. I have two options:

  1. Implements those interfaces in a single class.

  2. Seperate interfaces between classes:

    class X: public A, public B 
    {
    public:
        //impl
        const Data& getData();
    
    private:
        Data data;
    };
    
    class Y: public C
    {
    public:
        //impl use getData 
    
    private:
        X x;
    };
    
    

Which design is better ? Do you have some other ideas ?

Aucun commentaire:

Enregistrer un commentaire