您的位置:首页 > 理论基础 > 数据结构算法

大话数据结构 外观模式

2013-05-01 15:39 381 查看
package org.ustc.facade;

public class Fund {
private NationDebt dn;
private Realty realty;
private Stock stock;

public Fund() {
dn = new NationDebt();
realty = new Realty();
stock = new Stock();
}
public void buy(){
dn.buy();
realty.buy();
stock.buy();
}
public void sell(){
dn.sell();
realty.sell();
stock.sell();
}
}
package org.ustc.facade;

public class NationDebt {
public void buy(){
System.out.println("购买国债");
}
public void sell(){
System.out.println("卖出国债");
}
}
package org.ustc.facade;

public class Realty {
public void buy(){
System.out.println("购买了房地产");
}
public void sell(){
System.out.println("卖出房产");
}
}

package org.ustc.facade;

public class Stock {
public void buy(){
System.out.println("购买股票");
}
public void sell(){
System.out.println("卖出股票");
}
}

package org.ustc.facade;

public class Main {
public static void main(String[] args) {
Fund fund = new Fund();
fund.buy();
fund.sell();
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息