当前位置:网站首页>Factorymethod factory method
Factorymethod factory method
2022-06-25 22:04:00 【Daily enlightenment】
Convenient product dimension extension .
(1)CarFactory
public class CarFactory {
public Moveable create() {
System.out.println("a car created!");
return new Car();
}
}
(2)BroomFactory
public class BroomFactory {
public Moveable create() {
System.out.println("a Broom created!");
return new Broom();
}
}(3)Moveable
public interface Moveable {
void go();
}
(4)Car
public class Car implements Moveable {
@Override
public void go() {
System.out.println("Car go ....");
}
}(5)Broom
public class Broom implements Moveable{
@Override
public void go() {
System.out.println("broom flying .....");
}
}(6)Main
public class Main {
public static void main(String[] args) {
//Moveable m = new CarFactory().create();
//m.go();
Moveable m = new BroomFactory().create();
m.go();
}
}边栏推荐
- Mathematical analysis_ Notes_ Chapter 4: continuous function classes and other function classes
- Presto中Limit算子的处理过程
- Free cloud function proxy IP pool just released
- Common singleton functions traverse dictionary functions
- Jmeter- (I) installation of interface test
- 熊市指南|一些本质的教训与具体的生存法则
- Summary of digital image processing knowledge points
- Illustration de l'exécution du cadre de pile
- Adaptive streaming playback statistics set
- Obsidian基础教程
猜你喜欢

用idea建立第一个网站

Summary of digital image processing knowledge points

About the version mismatch of unity resource package after importing the project

3.4 cloning and host time synchronization of VMware virtual machine

Zero Trust: break the passive development mode of "attack and defense" and build a "moat" for enterprise safety

24 pictures to clarify TCP at one time

Build the first website with idea

【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧

Dbeaver offline installation driver

Php7.4 arm environment compilation and installation error invalid 'ASM': invalid operate prefix '%c'
随机推荐
Local Yum source production
Is it safe to open an account with Caicai securities?
Will neuvector be the next popular cloud native security artifact?
be careful! This written examination method is gradually being replaced
Common singleton functions traverse dictionary functions
Tcapulusdb Jun · industry news collection (VI)
ASC - DAY2
Did you really learn the right game modeling with 3DMAX?
【Proteus仿真】Arduino UNO花样流水灯
The robotframework executes CMD commands and bat scripts
Is there any risk for CICC fortune to open an account? Is it safe to open an account?
Winget: the "Winget" item cannot be recognized as the name of cmdlet, function, script file or runnable program. Win11 Winget cannot be used to solve this problem
Mastering quantization technology is the key to video compression
leetcode: 49. Grouping of alphabetic words
Canoe learning notes (2)
How does idea package its own projects into jar packages
Ecu-test report converted to excel format
PHP runtime and memory consumption statistics code
[HNU summer semester] preparation stage of database system design
HNU network counting experiment: experiment I application protocol and packet analysis experiment (using Wireshark)