Код: Выделить всё
struct Thing1 {
public:
void bar(class Implementation1 &i) {
i.baz();
}
// ...various other methods like bar()
};
struct Thing2 {
public:
void bar(class Implementation2 &i) {
i.qux();
}
// ...various other methods like bar()
};
< /code>
даны. К сожалению, эти классы фиксируются, то есть не могут быть изменены/рефакторированы.
Однако реализация1
Код: Выделить всё
template
struct ImplementationBase {
public:
S *self;
void foo() {
T thing;
thing.bar(*self);
}
// ...lots more shared code like foo()
};
< /code>
и конкретные реализации < /p>
struct Implementation1 : public ImplementationBase {
public:
Implementation1() {
self = this;
}
void baz() {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/27494072/refactoring-tightly-coupled-classes-when-only-one-side-can-be-changed[/url]