首页 > 程序开发 > Web开发 > ASP.Net >

设计模式之Facade——家庭篇

2006-07-14

1、  在这里,先定义家庭的各个成员类: 妻子(Wife): public class Wife {   protected Wife() {     System.out.println("老婆伟大 !");   } } 女儿(Daughter): public cl

1、 在这里,先定义家庭的各个成员类:

妻子(Wife):

public class Wife {

protected Wife() {

System.out.println("老婆伟大 !");

}

}

女儿(Daughter):

public class Daughter {

protected Daughter () {

System.out.println("女儿可爱 !");

}

}

我(Me):

public class Me {

protected Me() {

System.out.println("我爱我家 !");

}

}

2、定义家庭对外展现(FamilyOutShow)类:

public class FamilyOutShow {

public void MyFamily() {

Wife myWife = new Wife(); //我的老婆

Daughter myDaughter = new Daughter (); //我的女儿

Me me= new Me(); //我自己

}

}

3、编写测试类:

热点推荐