molamola
molamola

Reputation: 269

Does adapter pattern is used in my class diagram?

I did my homework that makes some program which has to use adapter pattern.

But I'm not sure about I used adaptor pattern in homework.

Can you check my diagram and adaptor pattern used?

enter image description here

I designed Car, Plane, Submarine as a adaptor classes which connect Vehicle super class and PrintStates interface.

Am I right?


There are 5 menu options (P)lane, (C)ar, (S)ubmarine, (B)lackbox, (H)alt and if user input button P/C/S, then all states of that object has shown, button B is the history of user's select and states of objects. Lastly, button H is to exit program.

Below is the execution of program.

enter image description here

Upvotes: 1

Views: 339

Answers (1)

Thiyagu
Thiyagu

Reputation: 17880

You use the Adapter pattern to convert the interface of a class into another interface the client expects.

Usually, the application of the adapter pattern involves a target interface, an implementation of the target interface and an adaptee interface. The application of Adapter I like the most is to convert Enumeration as an Iterator.

In your work, classes Car, Plane and Submarine extends Vehicle and they all implement PrintStates. Plane and Submarine override some of the methods in the Vehicle. Without knowing your requirement, it is difficult to understand why that is. But, I cannot see the application of the Adapter pattern here.


It would be useful if you can edit your post stating how you intended to implement the Adapter pattern here so that we can help you get your design right.

Upvotes: 2

Related Questions