The adapter pattern(structural design pattern) allows two unrelated interfaces to work together.
I assume that your company has built an Human Resource Management
application. An employee can be an Engineer/Senior Engineer/Manager.
And your company just buy a library that support this application
about Salary Management. But this library calls Engineer as Junior.
Engineer has a showInfo() method but Junior has a ShowEmployeeInfo().
If we don't use Adapter pattern then whenever we want to show
the employee information, we have to make an if statement
if object is Engineer then object.showInfo()
else object.ShowEmployeeInfo();
It makes the code become complex. We apply Adapter pattern
to solve this problem.
Steps to implements
1. Create a JuniorToEngineerAdapter class extends from Employee class
2. Before creating JuniorToEngineerAdapter above, we also create:
Employee, Engineer classes for my application.
The Employee class contains showInfo() methods.
Engineer class extends Employee
Junior class to simulate for the third party library
The Junior contains showEmployeeInfo() methods
3. Create a demo class that manage a list of employee
Auf dieser Seite können Sie das Online-Video Using the Adapter Design Pattern in Java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Improve Your Programming skills 21 September 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 119 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!