当前位置:网站首页>AbstractFactory Abstract Factory
AbstractFactory Abstract Factory
2022-06-25 22:04:00 【Daily enlightenment】
Easy to extend the product family .
(1)AbastractFactory
public abstract class AbastractFactory {
abstract Food createFood();
abstract Vehicle createVehicle();
abstract Weapon createWeapon();
}(2)Weapon
Adjectives use interfaces , Nouns use abstract classes .
public abstract class Weapon {
abstract void shoot();
}(3)Vehicle
public abstract class Vehicle {
abstract void go();
}(4)Food
public abstract class Food {
abstract void printName();
}(5)ModernFactory
public class ModernFactory extends AbastractFactory {
@Override
Food createFood() {
return new Bread();
}
@Override
Vehicle createVehicle() {
return new Car();
}
@Override
Weapon createWeapon() {
return new AK47();
}
}(6) AK47
public class AK47 extends Weapon{
public void shoot() {
System.out.println("tututututu....");
}
}(7)Car
public class Car extends Vehicle{
public void go() {
System.out.println("Car go wuwuwuwuw....");
}
}(8)Bread
public class Bread extends Food{
public void printName() {
System.out.println("wdm");
}
}(9)MagicFactory
public class MagicFactory extends AbastractFactory {
@Override
Food createFood() {
return new MushRoom();
}
@Override
Vehicle createVehicle() {
return new Broom();
}
@Override
Weapon createWeapon() {
return new MagicStick();
}
}
(10)MagicStick
public class MagicStick extends Weapon{
public void shoot() {
System.out.println("diandian....");
}
}(11)Broom
public class Broom extends Vehicle{
public void go() {
System.out.println("Car go wuwuwuwuw....");
}
}(12)MushRoom
public class MushRoom extends Food{
public void printName() {
System.out.println("dmg");
}
}(13)Main
public class Main {
public static void main(String[] args) {
AbastractFactory f = new ModernFactory();
//AbastractFactory f = new MagicFactory();
Vehicle c = f.createVehicle();
c.go();
Weapon w = f.createWeapon();
w.shoot();
Food b = f.createFood();
b.printName();
}
}边栏推荐
- Top in the whole network, it is no exaggeration to say that this Stanford machine learning tutorial in Chinese notes can help you learn from the beginning to the mastery of machine learning
- Jmeter- (IV) regular expression for interface testing
- Measurement fitting based on Halcon learning -- Practice [2]
- Did you really learn the right game modeling with 3DMAX?
- After osx-kvm modifies EFI, oc: failed to load configuration, osx-kvm generates opencore Qcow2 reports an error, libguestfs: error: source '
- idea怎么把自己的项目打包成jar包
- 24 pictures to clarify TCP at one time
- Jmeter- (III) create user test cases for interface testing
- Win11无法删除文件夹怎么办?Win11无法删除文件夹的解决方法
- 数学分析_笔记_第4章:连续函数类和其他函数类
猜你喜欢

Free your hands and automatically brush Tiktok

Windows11 windows security center cannot open Windows Defender cannot open

Hard liver! Super detailed basic introduction to Matplotlib!!!

Obsidian基础教程

用idea建立第一個網站

Understand which C standards are there & understand the C compilation pipeline

Bear market guide | some essential lessons and specific survival rules

Zhiyun health is about to go public: long-term losses, meinian health Yu Rong has withdrawn, and it is difficult to be optimistic about the future

24 pictures to clarify TCP at one time

3.4 cloning and host time synchronization of VMware virtual machine
随机推荐
Guidelines for implementing dns-sd in an NMOS environment
Set eye color
Ecu-test report converted to excel format
multiplication table
SSH modifies grub in heiqunhui ds918+ system 7.0.1 cfg
Introduction to HNU database system ODBC
Concept and understanding of variables
Measurement fitting based on Halcon learning -- Practice [2]
Some websites used by Beijing University of technology when graduating
Free cloud function proxy IP pool just released
Type conversion basis
图解栈帧运行过程
[proteus simulation] Arduino uno+ key controls 2-bit digital tube countdown
SOCKET编程部分I/O的初步解决
Writing manuals using markdown
[动态规划]最长回文子串-对于动态转移循环顺序的思考
Win11开始菜单右键空白?Win11开始菜单右键没反应解决方法
The latest (2022-2-16) vulnerability of WordPress plug-in bee collection (XSS, WordPress user name exposure, arbitrary article publishing) is repeated
STM32F103RCT6
【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧