diff --git a/src/com/msb/abstractFactory/AK47.java b/src/com/msb/abstractFactory/AK47.java new file mode 100644 index 0000000..535e8f5 --- /dev/null +++ b/src/com/msb/abstractFactory/AK47.java @@ -0,0 +1,20 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 15:40 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName AK47 + *@Description TODO + *@Author bingor + *@Date 2022/10/8 15:40 + *@Version 3.0 + */ +public class AK47 extends Weapon { + @Override + public void shoot() { + System.out.println("AK47 shoot……"); + } +} diff --git a/src/com/msb/abstractFactory/AbstractFactory.java b/src/com/msb/abstractFactory/AbstractFactory.java new file mode 100644 index 0000000..b843a60 --- /dev/null +++ b/src/com/msb/abstractFactory/AbstractFactory.java @@ -0,0 +1,19 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 16:42 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName AbstractFactory + *@Description TODO + *@Author bingor + *@Date 2022/10/8 16:42 + *@Version 3.0 + */ +public abstract class AbstractFactory { + public abstract Food createFood(); + public abstract Weapon createWeapon(); + public abstract Vehicle createVehicle(); +} diff --git a/src/com/msb/abstractFactory/Bread.java b/src/com/msb/abstractFactory/Bread.java new file mode 100644 index 0000000..9136d5f --- /dev/null +++ b/src/com/msb/abstractFactory/Bread.java @@ -0,0 +1,20 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 15:41 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName Bread + *@Description TODO + *@Author bingor + *@Date 2022/10/8 15:41 + *@Version 3.0 + */ +public class Bread extends Food { + @Override + public void printName() { + System.out.println("eat bread……"); + } +} diff --git a/src/com/msb/abstractFactory/Car.java b/src/com/msb/abstractFactory/Car.java new file mode 100644 index 0000000..c9a93ba --- /dev/null +++ b/src/com/msb/abstractFactory/Car.java @@ -0,0 +1,20 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 15:39 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName Car + *@Description TODO + *@Author bingor + *@Date 2022/10/8 15:39 + *@Version 3.0 + */ +public class Car extends Vehicle { + @Override + public void go() { + System.out.println("car go……"); + } +} diff --git a/src/com/msb/abstractFactory/Food.java b/src/com/msb/abstractFactory/Food.java new file mode 100644 index 0000000..1030a1f --- /dev/null +++ b/src/com/msb/abstractFactory/Food.java @@ -0,0 +1,17 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 16:43 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName Food + *@Description TODO + *@Author bingor + *@Date 2022/10/8 16:43 + *@Version 3.0 + */ +public abstract class Food { + public abstract void printName(); +} diff --git a/src/com/msb/abstractFactory/Main.java b/src/com/msb/abstractFactory/Main.java new file mode 100644 index 0000000..33862bc --- /dev/null +++ b/src/com/msb/abstractFactory/Main.java @@ -0,0 +1,25 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 16:23 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/8 16:23 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + AbstractFactory factory = new ModernFactory(); + Vehicle vehicle = factory.createVehicle(); + vehicle.go(); + Weapon weapon = factory.createWeapon(); + weapon.shoot(); + Food food = factory.createFood(); + food.printName(); + } +} diff --git a/src/com/msb/abstractFactory/ModernFactory.java b/src/com/msb/abstractFactory/ModernFactory.java new file mode 100644 index 0000000..3d544a2 --- /dev/null +++ b/src/com/msb/abstractFactory/ModernFactory.java @@ -0,0 +1,30 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 16:55 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName ModernFactory + *@Description TODO + *@Author bingor + *@Date 2022/10/8 16:55 + *@Version 3.0 + */ +public class ModernFactory extends AbstractFactory { + @Override + public Food createFood() { + return new Bread(); + } + + @Override + public Weapon createWeapon() { + return new AK47(); + } + + @Override + public Vehicle createVehicle() { + return new Car(); + } +} diff --git a/src/com/msb/abstractFactory/Vehicle.java b/src/com/msb/abstractFactory/Vehicle.java new file mode 100644 index 0000000..cca678f --- /dev/null +++ b/src/com/msb/abstractFactory/Vehicle.java @@ -0,0 +1,17 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 16:44 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName Vehicle + *@Description TODO + *@Author bingor + *@Date 2022/10/8 16:44 + *@Version 3.0 + */ +public abstract class Vehicle { + public abstract void go(); +} diff --git a/src/com/msb/abstractFactory/Weapon.java b/src/com/msb/abstractFactory/Weapon.java new file mode 100644 index 0000000..f1b6856 --- /dev/null +++ b/src/com/msb/abstractFactory/Weapon.java @@ -0,0 +1,17 @@ +package com.msb.abstractFactory;/** + * @Author bingor + * @Date 2022/10/8 16:43 + * @Description: com.msb.abstractFactory + * @Version: 1.0 + */ + +/** + *@ClassName Weapon + *@Description TODO + *@Author bingor + *@Date 2022/10/8 16:43 + *@Version 3.0 + */ +public abstract class Weapon { + public abstract void shoot(); +} diff --git a/src/com/msb/factory/Car.java b/src/com/msb/factory/Car.java new file mode 100644 index 0000000..c72015c --- /dev/null +++ b/src/com/msb/factory/Car.java @@ -0,0 +1,20 @@ +package com.msb.factory;/** + * @Author bingor + * @Date 2022/10/8 14:49 + * @Description: com.msb.factory + * @Version: 1.0 + */ + +/** + *@ClassName Car + *@Description TODO + *@Author bingor + *@Date 2022/10/8 14:49 + *@Version 3.0 + */ +public class Car implements Moveable { + @Override + public void go() { + System.out.println("car go"); + } +} diff --git a/src/com/msb/factory/CarFactory.java b/src/com/msb/factory/CarFactory.java new file mode 100644 index 0000000..5e60891 --- /dev/null +++ b/src/com/msb/factory/CarFactory.java @@ -0,0 +1,20 @@ +package com.msb.factory;/** + * @Author bingor + * @Date 2022/10/8 15:08 + * @Description: com.msb.factory + * @Version: 1.0 + */ + +/** + *@ClassName CarFactory + *@Description TODO + *@Author bingor + *@Date 2022/10/8 15:08 + *@Version 3.0 + */ +public class CarFactory { + public Moveable create() { + System.out.println("a car create"); + return new Car(); + } +} diff --git a/src/com/msb/factory/Main.java b/src/com/msb/factory/Main.java new file mode 100644 index 0000000..96d4333 --- /dev/null +++ b/src/com/msb/factory/Main.java @@ -0,0 +1,20 @@ +package com.msb.factory;/** + * @Author bingor + * @Date 2022/10/8 14:51 + * @Description: com.msb.factory + * @Version: 1.0 + */ + +/** + *@ClassName Main + *@Description TODO + *@Author bingor + *@Date 2022/10/8 14:51 + *@Version 3.0 + */ +public class Main { + public static void main(String[] args) { + Moveable m = new CarFactory().create(); //or new PlaneFactory().create() + m.go(); + } +} diff --git a/src/com/msb/factory/Moveable.java b/src/com/msb/factory/Moveable.java new file mode 100644 index 0000000..106805f --- /dev/null +++ b/src/com/msb/factory/Moveable.java @@ -0,0 +1,11 @@ +package com.msb.factory; + +/** + * @Author bingor + * @Date 2022/10/8 14:58 + * @Description: com.msb.factory + * @Version: 1.0 + */ +public interface Moveable { + public void go(); +} diff --git a/src/com/msb/factory/Plane.java b/src/com/msb/factory/Plane.java new file mode 100644 index 0000000..cd8a6b7 --- /dev/null +++ b/src/com/msb/factory/Plane.java @@ -0,0 +1,20 @@ +package com.msb.factory;/** + * @Author bingor + * @Date 2022/10/8 14:49 + * @Description: com.msb.factory + * @Version: 1.0 + */ + +/** + *@ClassName Car + *@Description TODO + *@Author bingor + *@Date 2022/10/8 14:49 + *@Version 3.0 + */ +public class Plane implements Moveable { + @Override + public void go() { + System.out.println("plane fly……"); + } +} diff --git a/src/com/msb/factory/SimpleVehicleFactory.java b/src/com/msb/factory/SimpleVehicleFactory.java new file mode 100644 index 0000000..4ce0db8 --- /dev/null +++ b/src/com/msb/factory/SimpleVehicleFactory.java @@ -0,0 +1,26 @@ +package com.msb.factory;/** + * @Author bingor + * @Date 2022/10/8 15:04 + * @Description: com.msb.factory + * @Version: 1.0 + */ + +/** + *@ClassName VehicleFactory + *@Description TODO + *@Author bingor + *@Date 2022/10/8 15:04 + *@Version 3.0 + */ +public class SimpleVehicleFactory { + + public Car createCar() { + //before processing 例如权限,日志等处理 + return new Car(); + } + + public Plane createPlane() { + return new Plane(); + } + +}