1

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

molamola
  • 269
  • 4
  • 15
  • Seems only a simple inheritance and polymorphism is what you have used and it suffices in this case – Thiyagu Mar 31 '18 at 13:11
  • This is not a question for StackOverflow. It belongs on [CodeReview](https://codereview.stackexchange.com). – jaco0646 Mar 31 '18 at 13:17

1 Answers1

2

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.

Thiyagu
  • 17,362
  • 5
  • 42
  • 79