zoukankan      html  css  js  c++  java
  • 工厂方法-抽象工厂

    工厂方法就是定制

    public class car{
        public void go(){        
            System.out.println("Car go");
        }
        Car c = new car();
        c.go();
    }
    
    public class Plane(){
        public void go(){
            System.out.println("Plane go");    
        }
    }
    
    public class Broom implements Moveable{
        public void go(){
            System.out.println("Broom go");    
        }
    }
    
    public class VehicleFactory{
        publc Car createCar(){
            // coding
            return new Car();
        }
    
        public Broom createBroom(){
            return new Broom();
        }
    }
    
    public class CarFactory{
        publc Car createCar(){
            // coding
            return new Car();
        }
        
        public Broom createBroom(){
            return new Broom();
        }
    }
    
    public class Weapon{
    
    }
    
    public class Bread{
    
    }
    
    public abstract class AbstractFactory{
        abstract Food createFood();
        abstract Vehilce createVehicle();
        abstract Weapon createWeapon();
    }
    
    public class ModernFactory extends AbstractFactory{
    
        Fool createFood(){
            return new Bread();
        }
    
        Vehicle createVehicle(){
            return new Vehicle();
        }
    
        Weapon createWeapon(){
            return new Weapon();
        }    
    }
    
    public class Main(){
        public static void main(String[] args){    
            Moveable m = new Broom();
            m.go();
            Plane plane = new Plane();
            p.go();    
            Moveable m = new CarFactory().createCar();
            m.go();
            AbstractFactory f = new ModernFacory();
        }
    }
    论读书
    睁开眼,书在面前
    闭上眼,书在心里
  • 相关阅读:
    mongo
    CSS常用属性
    nginx-proxy_cache缓存
    nginx防盗链
    oracle11g-centos部署
    VLAN高级特性
    路由
    网络摄像头分辨率
    前端开发调试线上代码的两款工具
    sql中 in , not in , exists , not exists效率分析
  • 原文地址:https://www.cnblogs.com/YC-L/p/14250921.html
Copyright © 2011-2022 走看看