Using the Adapter Design Pattern in Java

Pubblicato il: 21 settembre 2020
sul canale di: Improve Your Programming skills
119
4

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


In questa pagina del sito puoi guardare il video online Using the Adapter Design Pattern in Java della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Improve Your Programming skills 21 settembre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 119 volte e gli è piaciuto 4 spettatori. Buona visione!