Implement adapter pattern design using abstract classes and interfaces. The classes and interfaces involved are buttonlistener (interfaces), respectively,
It contains the click ()/Dbclick ()/keyUp ()/KeyDown () methods.
Buttonadapter (Button adapter class), the default implementation of the non-click () method in the adapter.
Add the AddListener (Buttonlistener L) method to the Button class.
*/
/*
Interface Buttonlistener {
public abstract void Click ();
public abstract void Dbclick ();
public abstract void keyUp ();
public abstract void KeyDown ();
}
Abstract class Buttonadapter implements Buttonlistener {
public void Dbclick () {};
public void KeyUp () {};
public void KeyDown () {};
}
Class MyButton extends Buttonadapter {
String name;
Public MyButton (String name) {
THIS.name = name;
}
public void Click () {
SYSTEM.OUT.PRINTLN (name);
}
}
Class Button {
Buttonlistener l;
public void AddListener (Buttonlistener l) {
THIS.L = l;
}
public void Click () {
L.click ();
}
}
Class Demo {
public static void Main (string[] arge) {
Button B = New button ();
B.addlistener (New MyButton ("1"));
B.click ();
Button B2 = New button ();
B2.addlistener (New MyButton ("2"));
B2.click ();
}
}
*/
/*
Explain what polymorphism is.
Why can functions be overwritten, and properties cannot be overwritten?
For:
Definition: The various forms of existence of a certain class of things.
For inherited classes, use the parent class type to refer to the object of the child class.
For an interface, you can use an interface to reference an object that is created by a class that implements the interface.
A property is an asset that holds data where the function is behaving, does not hold and stores data, so functions can be overwritten, and properties cannot.
*/
/*
Class Person {
String name;
public void Show () {
SYSTEM.OUT.PRINTLN (name);
}
}
Class Man extends person{
String name;
public void Show () {
System.out.println (Super.name);
SYSTEM.OUT.PRINTLN (name);
}
}
Class Demo {
public static void Main (string[] arge) {
Person p = new Mans ();
P.name = "Ererzizi";
P.show ();
}
}
*/
Java Foundation Sixth Day