How to merge the same method of different classes in the clean way

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 1384 Views - Last Post: 15 December 2011 - 09:18 PM Rate Topic: -----

#1 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

How to merge the same method of different classes in the clean way

Posted 13 December 2011 - 06:41 PM

Hi everybody..

I'm developing an application using Qt, but I need some advices regarding sharing class members.
I am working with some collections (QHash) of project-specific structs and I created a polymorphic class to manage those collections. A derived class also manage some UI components (shared through pointers or references) so it can automatically represent those structs in the UI.. It's something like this:

Main class

class ArmyEditor : public QMainWindow
{
//.... some specific functions ...

private:
    Ui::ArmyEditor *ui;

    // Specific structs
    QHash<QString, GameCategory> categories;
    QHash<QString, Column> columns;
    QHash<QString, GameProperty> properties;
    QHash<QString, UnitOption> commonOptions;
    QHash<QString, UnitOption> inheritedOptions;
    QHash<QString, GameItem> items;
    QHash<QString, GameItem> inheritedItems;
    QHash<QString, GlobalText> globalTexts;
    QHash<QString, GlobalText> inheritedGlobalTexts;
    QHash<QString, Unit> units;
};


Base class for collection managing..

class StructManager : public QObject {
    Q_OBJECT
public:

    explicit StructManager(QWidget* parent = 0);

    // ...Functions that perform actions in shared components...

protected:
    QWidget *parent;
    QHash<QString, GameCategory> *categories;
    QHash<QString, Column> *columns;
    QHash<QString, GameProperty> *properties;
    QHash<QString, UnitOption> *commonOptions;
    QHash<QString, GameItem> *commonItems;
    QHash<QString, GlobalText> *globalTexts;
    QHash<QString, Unit> *units;
};


Derived class for UI management and so on

class StructEditor : public StructManager
{
    Q_OBJECT
public:

    StructEditor(QWidget* parent = 0);

    // ...Overriden functions to automatically represent structs in the shared members..

protected:
    QTreeWidget *catList;
    QListWidget *colList;
    QTreeWidget *propList;
    QTreeWidget *optList;
    QListWidget *optActionList;
    QTreeWidget *itemList;
    QListWidget *itemActionList;
    QTableWidget *globalTextsGrid;
    QTreeWidget *unitTree;
    QComboBox *optCategory;
    QComboBox *itemCategory;
    QComboBox *unitCategory;
    QComboBox *optAmountColumn;
    QComboBox *optSetColumn;
};


And I share some UI members in the constructor of the MainWindow class..

ArmyEditor::ArmyEditor(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ArmyEditor)
{
    ui->setupUi(this);
    
    // Setup Army Struct Manager

    armyManager = new StructEditor(this);

    armyManager->setCatList(ui->catList);
    armyManager->setOptList(ui->optList);
    armyManager->setOptActionList(ui->optActionList);
    armyManager->setItemList(ui->itemList);
    armyManager->setItemActionList(ui->itemActionList);
    armyManager->setGlobalTextsGrid(ui->globalTextsGrid);
    armyManager->setUnitTree(ui->unitTree);
    armyManager->setOptCategory(ui->optCategory);
    armyManager->setItemCategory(ui->itemCategory);
    armyManager->setUnitCategory(ui->unitCategory);
    armyManager->setOptAmountColumn(ui->optAmountColumn);
    armyManager->setOptSetColumn(ui->optSetColumn);
    armyManager->setCategories(&categories);
    armyManager->setOptions(&commonOptions);
    armyManager->setItems(&items);
    armyManager->setGlobalTexts(&globalTexts);

    //.. some other code ..
};


I call the functions from the StructEditor class when I need to add a new Category or something like that..
My project consists of three applications, those of which use almost the same methods for managing these structs, so I decided to use a class with the methods to add, update, remove and represent the structs in the UI sharing some member pointers with the MainWindow class. But now I'm thinking it is a bit dirty and I should not share these members because the MainWindow loses control over them. I was thinking I could create the collections of my structs in the Base class and make a method so I can read (securely) members of those collections in the MainWindow class, but my problem is with UI members. I could use signals and manage those members directly in the MainWindow class, but then I would have to duplicate a lot of code and it would complicate (a bit) the code changes, which is the main reason I decided to unify those methods in a class.

So, my question is: Is there any way to 'unify' those methods without having to share members or using ugly global variables? I would like to have those methods in a separated file.

Thanks and greetings!

Is This A Good Question/Topic? 0
  • +

Replies To: How to merge the same method of different classes in the clean way

#2 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 13 December 2011 - 07:25 PM

It's a little bit hard to picture from your explanation exactly what you are trying to do. Perhaps you can create some minimal example that demonstrates what the problem is and what you are trying to accomplish.
Was This Post Helpful? 0
  • +
  • -

#3 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 13 December 2011 - 07:55 PM

Hi and thanks for answering!

I will try to explain my problem better..

I have some UI classes like ArmyEditor, GameEditor and UnitOption (just forms) which perform exactly the same actions when I want to add a 'category'. They all have a private "ui" member that contains every UI object.They all don't do the same and don't have the same purpose, but, for example, they represent the categories exactly in the same way. To avoid code-repeating, I decided to create a class that stores a pointer to some UI members and modifies them. For example:


class StructEditor : public StructManager
{
    Q_OBJECT
public:

    StructEditor(QWidget* parent = 0);
    
    virtual bool addCategory(const GameCategory &category, const QString &key);
    // ...Other methods that represent other types in the UI...

protected:
    QTreeWidget *catList;
    QListWidget *colList;
    QTreeWidget *propList;
    QTreeWidget *optList;
    QListWidget *optActionList;
    QTreeWidget *itemList;
    QListWidget *itemActionList;
    QTableWidget *globalTextsGrid;
    QTreeWidget *unitTree;
    QComboBox *optCategory;
    QComboBox *itemCategory;
    QComboBox *unitCategory;
    QComboBox *optAmountColumn;
    QComboBox *optSetColumn;
};


bool StructEditor::addCategory(const GameCategory &category, const QString &key) {
    if(catList && StructManager::addCategory(category, key)) {
        QStringList cells;
        cells << QString(category.getName());
        QTreeWidgetItem* item = new QTreeWidgetItem(cells);
        item->setData(0, Qt::UserRole, key);
        catList->topLevelItem(category.type)->addChild(item);
        catList->expandItem(catList->topLevelItem(category.type));

        if(category.type == GameCategory::CategoryOfOptions) {
            if(optList && optCategory) {
                item = new QTreeWidgetItem(cells);
                item->setData(0, Qt::UserRole, key);
                optList->addTopLevelItem(item);
                optCategory->addItem(category.getName(), key);
            }
        } else if(category.type == GameCategory::CategoryOfItems) {
            if(itemList && itemCategory) {
                item = new QTreeWidgetItem(cells);
                item->setData(0, Qt::UserRole, key);
                itemList->addTopLevelItem(item);
                itemCategory->addItem(category.getName(), key);
            }
        } else if(unitCategory && unitTree && category.type == GameCategory::CategoryOfUnits) {
            item = new QTreeWidgetItem(cells);
            item->setData(0, Qt::UserRole, QVariant(key));
            unitTree->addTopLevelItem(item);
            unitCategory->addItem(category.getName(), key);
        }
        return true;
    } else
        return false;
}


The StructEditor class avoids code-repeating, but I need to share private class members and I don't think it is a good idea because it reduces the control of such members, just like global variables. I could implement those methods in each UI class, but then I would have to update every file when I made a single change in that code, and I think that leads to bugs and simply makes updates 'harder'. So I'm looking for a way to have a single method that performs the UI changes without having to share private members.

I hope it explains better.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 04:41 PM

So if I understand correct your problem is something like this (very abstract)

You had

class ArmyEditor {
    ...
    public:
        void add_category(category);
    private:
        categories;
    ...
};

class GameEditor {
    ...
    public:
        void add_category(category);
    private:
        categories;
    ...
};



And you refactored this to

class ArmyEditor {
    ...
    private:
        categories;
        editor; //pass a pointer to categories to this editor
    ...
};

class GameEditor {
    ...
    
    private:
        categories;
        editor; //pass a pointer to categories to this editor
    ...
};

class StructEditor {
    public:
        void add_category(category);
    private:
        pointer to categories;
}



Is there any reason you can't make StructEditor a base of ArmyEditor, GameEditor and UnitOption, something like this:

class StructEditor {
    public:
        void add_category(std::string);
    private:
        categories; //not a pointer
};

class ArmyEditor : public StructEditor {
   ...
};

class GameEditor : public StructEditor {
   ...
};



There could be good reasons this obvious solution is not an option but what are they ?

This post has been edited by Karel-Lodewijk: 14 December 2011 - 04:46 PM

Was This Post Helpful? 1
  • +
  • -

#5 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 04:48 PM

Hi Karel-Lodewijk, thank you for answering!

Correct! You understood it completely right.I was thinking I could do what you suggest, but there is a minor problem: ArmyEditor and GameEditor have a private member called ui, which contains pointers to every UI object. Because the UI management code is exactly what I'm trying not to repeat, I can't have access to the UI members unless I create pointers in the 'base' (Editor in this case) class. I know it is a minimal problem, but it can lead to confusion when reading the code.

Greetings and again thanks!
Was This Post Helpful? 0
  • +
  • -

#6 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 05:08 PM

Yes a strange thing that ui, I'm not exactly certain what it does.

I read something like

ArmyEditor::ArmyEditor(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ArmyEditor)



So creating an army editor creates second army editor without a parent and puts a pointer to it in ui. It looks almost as if you are trying to build some kind of linked list of ArmyEditors.

You really going to have to explain this one.

This post has been edited by Karel-Lodewijk: 14 December 2011 - 05:08 PM

Was This Post Helpful? 0
  • +
  • -

#7 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 05:15 PM

Hi again!

Actually it does not create another ArmyEditor (notice the 'new Ui::ArmyEditor'), it just creates a ui member that contains every UI object. It is default in Qt: every UI component is inside a pointer called ui, so, for example, when I need to access to a UI member called 'spinBox1', I write ui->spinBox1 (please note ui is private).

Greetings!
Was This Post Helpful? 0
  • +
  • -

#8 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 05:32 PM

Now it makes sense, I assumed you just added an optional namespace before the class.

The Ui class is probably something automatically generated so you don't want to mess with it.

Have you considered a template approach. Put a pointer to the right ui in the base class but use templates to keep it usable as a base for all 3.

For example:

template <class UIType>
class StructEditor {
    public:
        void add_category(std::string);
    private;
        categories; //not a pointer
    protected:
        UIType* ui; //the right ui is now accessible
};

class ArmyEditor : public StructEditor<Ui::ArmyEditor> {
    ...
};

class GameEditor : public StructEditor<Ui::GameEditor> {
   ...
};



Templates are really the goto solution when you have some things that behave the same but it is impossible to put it into some kind of an inheritance scheme.


Hint:

Since your project is probably nicely split into cpp and h files and you don't want template classes to mess with that, put

template class StructEditor<Ui::ArmyEditor>;
template class StructEditor<Ui::GameEditor>;
template class StructEditor<Ui::UnitOption>;

At the end of the cpp file of StructEditor, it is an often overlooked alternative to putting all template code in the header file.

This post has been edited by Karel-Lodewijk: 14 December 2011 - 05:39 PM

Was This Post Helpful? 1
  • +
  • -

#9 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 07:50 PM

Hi again! Thanks for answering.

I was expecting something exactly like that!!! I was considering templates, but I have never used them before.. I have some general questions though:
1. You said the templates are problematic with inheritance.. Could you explain me why please?
2. As UiType is automatically replaced with the correct type, the ui of StructEditor is overriden by that variable in ArmyEditor/GameEditor?

Thanks a lot again!!!
Was This Post Helpful? 0
  • +
  • -

#10 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 14 December 2011 - 10:29 PM

Sorry for the double post, but New members cannot edit (I will contact a moderator to join these posts)..

(Updated)2. As UiType is automatically replaced with the correct type, the ui of StructEditor is overriden by that variable in ArmyEditor/GameEditor? Does it matter the fact that 'ui' is private in ArmyEditor? I think it doesn't matter and I can override the access level, but I'm not sure.
3. Will I be able to inherit from different classes like that? For example:

template <class UIType>
class CategoryDrawer {
public slots:
    void categoryAdded(const GameCategory& category, const QString& key);
    void categoryRemoved(const QString& key);
protected:
    UIType* ui;
};

template <class UIType>
class ColumnDrawer {
public slots:
    void columnAdded(const Column& column, const QString& key);
    void columnRemoved(const QString& key);
protected:
    UIType* ui;
};

template <class UIType>
class ItemDrawer {
public slots:
    void itemAdded(const GameItem& item, const QString& key);
    void itemRemoved(const QString& key);
protected:
    UIType* ui;
};

class ArmyEditor : public CategoryDrawer<Ui::ArmyEditor>, 
                   public ColumnDrawer<Ui::ArmyEditor>,
                   public ItemDrawer<Ui::ArmyEditor>, 
                   QMainWindow(parent),
                   ui(new Ui::ArmyEditor) {
    ...
};


Thanks and greetings!
Was This Post Helpful? 0
  • +
  • -

#11 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 15 December 2011 - 08:11 AM

View PostDaniel.Castro, on 14 December 2011 - 07:50 PM, said:

1. You said the templates are problematic with inheritance.. Could you explain me why please?


I didn't say problematic with inheritance. I said templates are a good alternative if an inheritance scheme poses problems as in your code.

View PostDaniel.Castro, on 14 December 2011 - 07:50 PM, said:

2. As UiType is automatically replaced with the correct type, the ui of StructEditor is overriden by that variable in ArmyEditor/GameEditor?


Basically you just wouldn't have a ui variable in ArmyEditor/GameEditor, just use the one you inherit (that's why I made it protected not private) ui will be the Ui::ArmyEditor for ArmyEditor class, Ui::GameEditor for the GameEditor classn, ... .

This post has been edited by Karel-Lodewijk: 15 December 2011 - 08:16 AM

Was This Post Helpful? 1
  • +
  • -

#12 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 15 December 2011 - 08:19 AM

Sorry, I misunderstood this part:

Quote

Templates are really the goto solution when you have some things that behave the same but it is impossible to put it into some kind of an inheritance scheme.


It's now clear.

Could you help me with my third question, please? I think it is the only thing left.

Thanks a lot, this is really really helpful.
Was This Post Helpful? 0
  • +
  • -

#13 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 15 December 2011 - 08:52 AM

View PostDaniel.Castro, on 14 December 2011 - 10:29 PM, said:

Sorry for the double post, but New members cannot edit (I will contact a moderator to join these posts)..

(Updated)2. As UiType is automatically replaced with the correct type, the ui of StructEditor is overriden by that variable in ArmyEditor/GameEditor? Does it matter the fact that 'ui' is private in ArmyEditor? I think it doesn't matter and I can override the access level, but I'm not sure.
3. Will I be able to inherit from different classes like that? For example:

Spoiler


Thanks and greetings!


You're touching on a whole new issue here. But yes it can be done.

So you want 1 ui, CategoryDrawer, ColumnDrawer, ItemDrawer must be able to use it. And ArmyEditor is a CategoryDrawer/ColumnDrawer/ItemDrawer.

Basically you want an inheritance scheme like this.

             Editor
          /    |   \
       /       |      \ 
    /          |         \
CaDrawer    CoDrawer   IDrawer
    \          |         /
       \       |      /
          \    |   /
           ArmyEditor



This is a variation of the diamond shaped inheritance. c++ allows you to do it. It does have some oddities so I'm going to give you an example and point them out.

#include <cassert>

//just making certain Ui::ArmyEditor exists
//obvious you won't beed this, you allready 
//have a Ui::ArmyEditor
namespace Ui {
    typedef int ArmyEditor;
}

template <class UiType>
class Editor {
    public:
        Editor() {assert(false);} 
        Editor(UiType* ui_) : ui(ui_) {} 
        ~Editor() {delete ui;}
    protected:
        UiType* ui;
};

template <class UiType>
class CategoryDrawer : public virtual Editor<UiType> {

};

template <class UiType>
class ColumnDrawer : public virtual Editor<UiType> { 

};

template <class UiType>
class ItemDrawer : public virtual Editor<UiType> {

};

class ArmyEditor : public CategoryDrawer<Ui::ArmyEditor>, 
                   public ColumnDrawer<Ui::ArmyEditor>, 
                   public ItemDrawer<Ui::ArmyEditor> {
    public:
        ArmyEditor() : Editor<Ui::ArmyEditor>(new Ui::ArmyEditor) {}
};

int main() {
    ArmyEditor amrmy_editor;
}



This one actually compiles.


First let me point out

class CategoryDrawer : public virtual Editor<UiType>
class ColumnDrawer : public virtual Editor<UiType>
class ItemDrawer : public virtual Editor<UiType> 



Notice the virtual.

This signifies to the compiler that no Editor<UiType> base needs to be created but one will be provided so they each use the same one. If you didn't have the virtual, the inheritance scheme would look like this.

  Editor     Editor    Editor
    |          |         |
    |          |         |
    |          |         |
CaDrawer    CoDrawer   IDrawer
    \          |         /
       \       |      /
          \    |   /
           ArmyEditor



It will be the responsibility of the most derived class to create this base. In this case ArmyEditor. That's why this code is there:

ArmyEditor() : Editor<Ui::ArmyEditor>(new Ui::ArmyEditor) {}



Also notice the ui is put right in the Editor base class. ArmyEditor has no ui pointer of it's own, it can access the ui from Editor. This is what I meant before.

ArmyEditor creates the Editor base for CategoryDrawer, ColumnDrawer and ItemDrawer.

Then

class ArmyEditor : public CategoryDrawer<Ui::ArmyEditor>, 
                   public ColumnDrawer<Ui::ArmyEditor>, 
                   public ItemDrawer<Ui::ArmyEditor> {



We make the 3 base classes real with the correct type filled in.

One last thing

Editor() {assert(false);} 



This is sort of a hack. We don't want Editor to be default constructible but we must for the compiler or we would have to create constructors for CategoryDrawer, ColumnDrawer and ItemDrawer that call the non-default constructor. We have no way of telling the compiler that we will only use CategoryDrawer, ColumnDrawer and ItemDrawer with a provided base and he shouldn't worry about the lack of a default constructor.

The assert however makes certain that if we were ever to call the default constructor, it will result in an immediate error.

This post has been edited by Karel-Lodewijk: 15 December 2011 - 10:30 AM

Was This Post Helpful? 2
  • +
  • -

#14 Daniel.Castro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 13-December 11

Re: How to merge the same method of different classes in the clean way

Posted 15 December 2011 - 09:24 AM

Hi again!

Wow, that's actually awesome!.

1. Before all, let me ask something that is probably obvious/stupid:
If the scheme looks like this:
    Ui         Ui       Ui
    |          |         |
    |          |         |
    |          |         |
CaDrawer    CoDrawer   IDrawer
    \          |         /
       \       |      /
          \    |   /
           ArmyEditor

In other words, if I attempt to do it as I did in my previous answer, won't be all that 'ui' members of CaDrawer, CoDrawer and IDrawer merged in just one (the one of ArmyEditor)? Maybe I will get compiler errors saying that 'ui' was already declared.

2. The default constructor is needed for the project to actually compile, but it is never called as CategoryDrawer, ColumnDrawer and ItemDrawer inherit from a virtual Editor, right?

3. What would happen if ArmyEditor inherited from CategoryDrawer (which inherits from a virtual Editor) and I never initialize with 'new Ui::ArmyEditor' in ArmyEditor's constructor?

Thanks a lot! This is just awesome!

Greetings!
Was This Post Helpful? 0
  • +
  • -

#15 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: How to merge the same method of different classes in the clean way

Posted 15 December 2011 - 09:56 AM

View PostDaniel.Castro, on 15 December 2011 - 09:24 AM, said:

In other words, if I attempt to do it as I did in my previous answer, won't be all that 'ui' members of CaDrawer, CoDrawer and IDrawer merged in just one (the one of ArmyEditor)? Maybe I will get compiler errors saying that 'ui' was already declared.


No they will not be merged.

The ui in ArmyEditor will shadow the ui in Editor. If you want to go that route it will be messier I think and cause some confusion but it can be done obviously.

View PostDaniel.Castro, on 15 December 2011 - 09:24 AM, said:

2. The default constructor is needed for the project to actually compile, but it is never called as CategoryDrawer, ColumnDrawer and ItemDrawer inherit from a virtual Editor, right?


Exactly. The virtual inheritance means, the most derived class must create the Editor base. In this case ArmyEditor and he doesn't use it.

I must point out this "most derived" is important.

Most derived is important, if you were to create a

class Derived : public ArmyEditor {
};



Then derived would have to create the Editor base. And so it sort of pollutes the encapsulation as you need to be aware of the virtual base in the Derived class.

Some literature will recommend you only create virtual bases with default constructors. This is not difficult, just initialize the ui pointer in the ArmyEditor constructor and use only a default Editor constructor.

View PostDaniel.Castro, on 15 December 2011 - 09:24 AM, said:

3. What would happen if ArmyEditor inherited from CategoryDrawer (which inherits from a virtual Editor) and I never initialize with 'new Ui::ArmyEditor' in ArmyEditor's constructor?


The default constructor of Editor will be used, the assert will be executed and the program will stop. Basically that's why the assert is there, so you don't forget to initialize the ui. I would rather not have a default constructor but then I would have to add constructors to CategoryDrawer, ColumnDrawer and ItemDrawer that I will never use. It's the lesser of 2 evils I think.

View PostDaniel.Castro, on 15 December 2011 - 09:24 AM, said:

Thanks a lot! This is just awesome!


Glad to help,

But don't get too caught up with this solution. It is something I might do, I don't mind using multiple inheritance to bring components together to create new but similar classes and it suits what you wanted to do.

But there are others who would look away in disgust if they see multiple inheritance and would much prefer your original solution, they are not necessary wrong. Many languages don't support multiple inheritance because it comes with it's own set of problems.

Find something that works for you.

EDIT: Pointed out the importance of the "most derived class is responsible" and possible issues with that.

This post has been edited by Karel-Lodewijk: 15 December 2011 - 10:34 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2