java静态代理动态代理理解和例子解析包含demo

demo

基本背景

// 背景: 有一家甜品点,有2类机器,面包和蛋糕机器, 接口 BreadMachine CakeMachine
//      面包机器有蜂蜜和黄油2种,类 BreadButter BreadBee
//      蛋糕机器有水果和巧克力2种,类 CakeFruit CakeChocolate
package com.ah.test.proxy.shop1;
// 面包机器
interface BreadMachine {
   
    void makeBread();
}
class BreadButter implements BreadMachine {
   
    public void makeBread() {
   
        System.out.println("制作黄油面包....");
    }
}
class BreadBee implements BreadMachine{
   
    public void makeBread() {
   
        System.out.println("制作蜂蜜面包...");
    }
}
// 蛋糕机器
interface CakeMachine {
   
    void makeCake();
}
class CakeFruit implements CakeMachine{
   
    public void makeCake() {
   
        System.out.println("制作水果蛋糕...");
    }
}
class CakeChocolate implements CakeMachine{
   
    public void makeCake() {
   
        System.out.println("制作巧克力蛋糕...");
    }
}
public class Test {
   
    public static void main(String[] args) {
   
        new BreadButter().makeBread();
        new BreadBee().makeBread();
        new CakeFruit().makeCake();
        new CakeChocolate

你可能感兴趣的:(java,java,python,开发语言)