dimanche 22 mars 2015

Design: Class circular dependency?

I've been reading different answers here about solving the circular dependency in software design and I still cann't get it. Please help me understand it.


Let's say I have class A and class B which call methods of each other:



class A {
public:
void Do1() {
B b;
b.Do1();
}

void Do2() {
//do something
}
};

class B {
public:
void Do1() {
//do something
}

void Do2() {
A a;
a.Do2();
}
};


Classes are perfectly devided according to Single responsibility principle.


It looks like I cann't apply Dependency Inversion Principle here as I can aggregate only one class into another.


According to best design practices could you suggest me the proper way on how to handle this?


I'd appreciate your answers with some code.


Aucun commentaire:

Enregistrer un commentaire