package com.swift; public class Baby_Baomu_ProxyFactory_Test { public static void main(String[] args) { /* * 有一个Baby类,有Cry行为,Baby可以配一个保姆, * 但是作为保姆,必须遵守保姆协议:能够处理Baby类Cry的行为,如喂奶、哄睡觉。 * 请根据以上描述设计一套代理设计模式 */ ProxyFactoryBaby baby=new ProxyFactoryBaby(new Baomu("一号保姆")); baby.cry(); } } class Baby{ public void cry() { System.out.println("哇哇哇,baby is crying......"); } } interface LookBabyProtocal{ void feedBaby(); void hongBaby(); } class Baomu implements LookBabyProtocal{ private String name; public Baomu(String name) { this.name=name; } @Override public void feedBaby() { System.out.println("Baomu feed baby.."); } @Override public void hongBaby() { System.out.println("Baomu hong baby.."); } } class ProxyFactoryBaby extends Baby{ Baomu baomu; public Baomu getBaomu() { return baomu; } public void setBaomu(Baomu baomu) { this.baomu = baomu; } public ProxyFactoryBaby(Baomu baomu) { this.baomu=baomu; } @Override public void cry() { super.cry(); baomu.feedBaby(); baomu.hongBaby(); } }