package liu.decorator.demo;
public class Person {
private String name;
public Person(){}
public Person(String name){
this.name = name;
}
public void show(){
System.out.println("decorate:"+name);
}
}
-----------------------------------------
package liu.decorator.demo;
private String name;
public Person(){}
public Person(String name){
this.name = name;
}
public void show(){
System.out.println("decorate:"+name);
}
}
-----------------------------------------
package liu.decorator.demo;
public class Finery extends Person{
protected Person component;
public void Decorate(Person component){
this.component= component;
}
public void show(){
if(component!=null){
component.show();
}
}
}
---------------------------------------
package liu.decorator.demo;
public void Decorate(Person component){
this.component= component;
}
public void show(){
if(component!=null){
component.show();
}
}
}
---------------------------------------
package liu.decorator.demo;
public class Shoot extends Finery{
public void show(){
System.out.println("球鞋");
super.show();
}
}
--------------------------------------
package liu.decorator.demo;
System.out.println("球鞋");
super.show();
}
}
--------------------------------------
package liu.decorator.demo;
public class TShirts extends Finery{
public void show(){
System.out.println("大T桖");
super.show();
}
}
-------------------------
package liu.decorator.demo;
System.out.println("大T桖");
super.show();
}
}
-------------------------
package liu.decorator.demo;
public class BigTrouser extends Finery{
public void show(){
System.out.println("垮裤");
super.show();
}
}
-----------------------------
package liu.decorator.demo;
System.out.println("垮裤");
super.show();
}
}
-----------------------------
package liu.decorator.demo;
public class Main {
public static void main(String[] args) {
Person xc = new Person("小菜");
System.out.println("第一种装扮:");
BigTrouser kk = new BigTrouser();
TShirts dtx = new TShirts();
Shoot st = new Shoot();
kk.Decorate(xc);
dtx.Decorate(kk);
st.Decorate(dtx);
st.show();
Person xc = new Person("小菜");
System.out.println("第一种装扮:");
BigTrouser kk = new BigTrouser();
TShirts dtx = new TShirts();
Shoot st = new Shoot();
kk.Decorate(xc);
dtx.Decorate(kk);
st.Decorate(dtx);
st.show();
}
}