Added UnitTest cases for adapter.

This commit is contained in:
mfarid
2015-11-22 05:44:45 +05:30
parent ba3f583467
commit b577890db4
5 changed files with 89 additions and 31 deletions
@@ -1,30 +1,28 @@
package com.iluwatar.adapter;
/**
*
* An adapter helps two incompatible interfaces to work together. This is the real world definition
* for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
* the interface of one class into an interface expected by the clients.
* <p>
* There are two variations of the Adapter pattern: The class adapter implements the adaptee's
*
* <p>There are two variations of the Adapter pattern: The class adapter implements the adaptee's
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
* object. This example uses the object adapter approach.
* <p>
* The Adapter ({@link GnomeEngineer}) converts the interface of the target class (
*
* <p>The Adapter ({@link GnomeEngineer}) converts the interface of the target class (
* {@link GoblinGlider}) into a suitable one expected by the client ({@link GnomeEngineeringManager}
* ).
*
*/
public class App {
/**
* Program entry point
*
* Program entry point.
*
* @param args command line args
*/
public static void main(String[] args) {
Engineer manager = new GnomeEngineeringManager();
Engineer manager = new GnomeEngineeringManager(new GnomeEngineer());
manager.operateDevice();
}
}
@@ -1,20 +1,26 @@
package com.iluwatar.adapter;
/**
*
* GnomeEngineering manager uses {@link Engineer} to operate devices.
*
*/
public class GnomeEngineeringManager implements Engineer {
private Engineer engineer;
public GnomeEngineeringManager() {
engineer = new GnomeEngineer();
}
public GnomeEngineeringManager(Engineer engineer) {
this.engineer = engineer;
}
@Override
public void operateDevice() {
engineer.operateDevice();
}
public void setEngineer(Engineer engineer) {
this.engineer = engineer;
}
}