Adapter classes and Listener Interfaces

Adapter classes and Listener Interfaces.

is because java want encapsulate fields, and when u use interfaces the aplication have less couple. then if u use everthing classes your application have more couple. then when an interface have an adapter class this means that adapter class implements all methos in the interface, and you only need override the methods that you want (about the class adapter), use too polymorphism. Use is:
WindowListener wl = new WindowAdapter();
then u can use all methods.
is normall in all Java Interfaces.

  public interface MyInterface{      public int count();      public void setAnValue(String anValue);      public String getAnValue();  }    

//... then u implement this interface Is an example

  public class MyInterfaceImpl implements myInterface{      String anValue;      public int count(){       return 1;      }      public void setAnValue(String anValue){          this.anValue = anValue;      }      public String getAnValue(){          return anValue;      }  }    

// now u can see the powerfull of this approach

  public class MyClassNew{      private MyInterface myIf = new MyInterfaceImpl;      //here this class can add new methods...      public int getValueZero(){          myIf.count() - 1;      }      public String getAnString(){          myIf.setAnValue("myStringValue");          return myIf.getAnValue();      }      //how u can see, i use the Interface methods, and instantiate to MyInterfaceImpl - here is polymorphism with less couple.    }    
Video Adapter classes and Listener Interfaces

Adapter classes and Listener Interfaces


Source: www.bing.com
Images credited to www.bing.com and upload.wikimedia.org


Related Posts To Adapter classes and Listener Interfaces


Adapter classes and Listener Interfaces Rating: 4.5 Posted by: Brot Trune

Search Here

Popular Posts

Total Pageviews

Recent Posts