This may sound confusing, but here goes. So I have two inferfaces, intoLogic and intoView, both of which are abstract classes. Both of them are derived to two classes, Logic and View. Basically, I want to have the class Logic call functions from interface intoView, that View will actually execute. Then I want to have the class View call functions from interface intoLogic, that Logic will actually execute. So basically, View calls a function from intoLogic, that actual Logic will execute and then Logic calls a function from intoView, that actual View will execute. So in code, it looks something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class intoLogic
{
public:
virtual void calculate() = 0;
};
class Logic: public intoLogic
{
public:
Logic();
void calculate();
private:
//A (unique) pointer of type intoView that points at View, so that I can
//call for instance pointertoview->showResult();
};
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class intoView
{
public:
virtual void showResult() = 0;
};
class View: public intoView
{
public:
View();
void showResult();
private:
//A (unique) pointer of type intoLogic that points at Logic, so that I can
//call for instance pointertologic->calculate();
};
|
So how do I create the unique pointers that way? Is it overall possible to have something like
std::unique_ptr<intoView> graphics(new View);
in the private of Logic, so that I can call graphics->showResult();?
When I try implementing it like that, I get a lot of problems trying to include everything needed in the classes. So how should I solve this? I was thinking about a factory method, where I create a separate module to assign the unique pointers, but is there an easier way?
EDIT: I tried doing it with the factory method, but it will just end up with the program stuck in an infinite loop. I'm out of ideas.