I have several classes with different interfaces and now I want to unify them. Here is an example in C++
class Add {
public:
void setOperand1(int o1) { operand1 = o1 };
void setOperand2(int o2) { operand2 = o2 };
private:
int operand1;
int operand2;
}
class Negate {
public:
void setOperand(int o) { operand = o; };
private:
int operand;
}
I want to unify the interfaces of the two. The adapter design pattern comes to my mind. While the drawback is that the adapter interface must be the union of the two adaptees, which may cause the interface exploding if later more operator class added in.
My question, is this a best practice to use Adapter in similar scenario? And any alternatives to make it interface exploding proof? Thank you.
Aucun commentaire:
Enregistrer un commentaire