Adapter mode:
Transforms the interface of one class into another interface that the customer wants. The adapter mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work together.
There are two types of adapter modes:
1) class adapter (by inheritance)
2) object Adapter (Takes object combination mode)
--------------------------Class Adapter-----------------------------
Target.java
[Java]View plain copy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- Package com.adapter;
- Public Interface Target
- {
- public void Method ();
- }
by adapter class
Adaptee.java
[Java]View plain copy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- Package com.adapter;
- Public class Adaptee
- {
- public void Method2 ()
- {
- System.out.println ("adapter-->method2 ()");
- }
- }
Adapter Class Adapter.java
[Java]View plain copy
- Package com.adapter;
- Public class Adapter extends Adaptee implements Target
- {
- public Void Method ()
- {
- super.method2 (); //or THIS.METHOD2 ();
- }
- }
Client.java
[Java]View plain copy
- Package com.adapter;
- Public class Client
- {
- public static void Main (string[] args)
- {
- Target t = new Adapter ();
- T.method ();
- }
- }
--------------------------Object Adapter-----------------------------
Target.java
[Java]View plain copy
- Package com.adapter;
- Public Interface Target
- {
- public void Method ();
- }
by adapter class
Adaptee.java
[Java]View plain copy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- Package com.adapter;
- Public class Adaptee
- {
- public void Method2 ()
- {
- System.out.println ("adapter-->method2 ()");
- }
- }
Adapter Class Adapter.java
[Java]View plain copy
- Package com.adapter;
- Public class Adapter implements Target
- {
- private Adaptee adaptee;
- Public Adapter (adaptee adaptee)
- {
- this.adaptee = adaptee;
- }
- public Void Method ()
- {
- this.adaptee.method2 ();
- }
- }
Client.java
[Java]View plain copy
- Package com.adapter;
- Public class Client
- {
- public static void Main (string[] args)
- {
- Adaptee adaptee = new Adaptee ();
- Target t = new Adapter (adaptee);
- T.method ();
- }
- }
Adapter (Adapter mode)