samedi 23 mai 2020

Adapter Design Pattern

I've recently came across this question and I'm just curious if my answer is correct, and if not, where I made a mistake.

My Task:

The signatures of classes A and B are incompatible. Class C is to connect A and B with the Design Pattern Adapter.

What are the advantages of having C inherit from A and B? Explain whether it would make sense to have B inherit from A and C inherit from B.

My answer:

The advantage of making C inherit from A and B is that the signature conflict can be resolved, while A and B could still be instantiated separately.

It would not make sense to have B inherit from A and C inherit from B, because if the functionality that previously caused the conflict is inherited from A to C, B has to take over the implementation of A, the functionality of B would be changed, this would not be the purpose of the design pattern adapter.

Thanks :-)

Aucun commentaire:

Enregistrer un commentaire