标注:可以添加到程序代码的任何元素(包声明、类型声明、构造方法、方法、成员变量、参数),用来设置一些说明和解释。
反射(Reflection):是指程序可以访问、检测和修改本身状态或行为的一种能力。
代理
静态代理:
顾客委托中介公司找服装厂做衣服。
public interface ClothingFactory {
void productClothing();//生产衣服的能力
}
public class LiNingCompany implements ClothingFactory{
@Override
public void productClothing() {
// TODO Auto-generated method stub
System.out.println("生产一批LiNing衣服");
}
}
public class ProxyCompany implements ClothingFactory{
ClothingFactory cf;
public ProxyCompany(ClothingFactory cf) {
// TODO Auto-generated constructor stub
this.cf=cf;
}
@Override
public void productClothing() {
// TODO Auto-generated method stub
System.out.println("收取中介费1000元");
cf.productClothing();
}
}
public class Customer {
public static void main(String[] args) {
// TODO Auto-generated method stub
ClothingFactory cf=new ProxyCompany(new LiNingCompany());
cf.productClothing();
}
}
运行结果:
收取中介费1000元
生产一批LiNing衣服