Adapter Design Patterns provides an interface between two unrelated entities so that they can work together.
One of the great real life example of Adapter design pattern is mobile charger. Mobile battery needs 3 volts to charge but the normal socket produces either 120V (US) or 240V (India). So the mobile charger works as an adapter between mobile charging socket and the wall socket.
Note- The Adapter Pattern is also known as Wrapper.
Advantage-
Example-
Some of the adapter design pattern example I could easily find in JDK classes are:
Note- The Adapter Pattern is also known as Wrapper.
Advantage-
- Helps achieve re-usability and flexibility.
- Client class is not complicated by having to use a different interface and can use polymorphism to swap between different implementations of adapters.
Example-
Some of the adapter design pattern example I could easily find in JDK classes are:
- JDBC API (Oracle Driver, MySQL Driver, PostgresSQL)
- java.util.Arrays#asList()
- java.io.InputStreamReader(InputStream) (returns a Reader)
- java.io.OutputStreamWriter(OutputStream) (returns a Writer)
Reference Link-
No comments:
Post a Comment