Adapter design pattern is one of the structural design pattern and is used so that two unrelated interfaces can work together. The object that joins these unrelated interface is called adapter.
A Good example is Socket and Mobile Charger. A regular wall socket produces 120 V but the mobile charger cable
Normally there will be a default implementation of a functionality and if a change is required an adapter is created.
There are two implementations for Adapters
1. One that extends the existing implementation and also the adapter interface
2. One that wraps the existing implementation and also implements the adapter interface.
both provide the same output
Another real time implementation may be Logger. There could be a network logger, file logger, a console logger. Which logger to be used we could specify in a property file and using Java Class loader we can load the implementation at run time
Class aClass = classLoader.loadClass("com.mytest.FileLogger”);
LoggerImpl limpl = (LoggerImpl) aClass;
References:
No comments:
Post a Comment