1、问题描述
小明想要购买一套房子,他决定寻求一家房屋中介来帮助他找到一个面积超过100平方米的房子,只有符合条件的房子才会被传递给小明查看。
输入示例
3
120
80
110
输出示例
YES
NO
YES
2、代理模式
代理模式是⼀种结构型设计模式,⽤于控制对其他对象的访问。
为了避免直接访问真实对象,可以新增⼀个代理对象,通过代理对象,可以在访问 真实对象 前后添加一些自己的逻辑,避免修改真实对象的代码。
3、代码
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int number=sc.nextInt();
for(int i=0;i<number;i++){
int price=sc.nextInt();
Proxy proxy=new Proxy();
proxy.Buy(new XiaoMing(),price);
}
}
}
interface Customer{
void Buy(Customer name,int price);
}
class XiaoMing implements Customer{
@Override
public void Buy(Customer name,int price) {
System.out.println("YES");
}
}
class Proxy implements Customer{
private Customer person;
@Override
public void Buy(Customer name,int price) {
this.person=name;
if(price<100){
System.out.println("NO");
return;
}
person.Buy(name,price);
}
}