public interface AppleSeller {
void privide(int quantity);
}
public class AppleSellerProxy implements AppleSeller {
private AppleSeller fakeSeller;
private AppleSeller certifiedProvider;
public AppleSellerProxy(){
fakeSeller=new FakeProvider();
certifiedProvider=new CertifiedProvider();
System.out.println("供应商找完了!");
}
@Override
public void privide(int quantity) {
if(quantity>100){
System.out.println("买的很多,给他一些假货!");
fakeSeller.privide(quantity/2);
certifiedProvider.privide(quantity-quantity/2);
return;
}
System.out.println("给真货!");
certifiedProvider.privide(quantity);
}
private class CertifiedProvider implements AppleSeller{
@Override
public void privide(int quantity) {
System.out.println("给你"+quantity+"个正品!");
}
}
private class FakeProvider implements AppleSeller{
@Override
public void privide(int quantity) {
System.out.println("给你"+quantity+"个假货!");
}
}
}
public class Client {
public static void main(String[] args) {
AppleSeller seller=new AppleSellerProxy();
seller.privide(10);
seller.privide(1000);
}
}