IOC设计模式的理解
来源:互联网 发布:淘宝网商品发布规则 编辑:程序博客网 时间:2024/06/03 19:18
抽象工厂模式代码
产品类:
- //发动机以及型号
- public interface Engine {
- }
- public class EngineA extends Engine{
- public EngineA(){
- System.out.println("制造-->EngineA");
- }
- }
- public class EngineBextends Engine{
- public EngineB(){
- System.out.println("制造-->EngineB");
- }
- }
- //空调以及型号
- public interface Aircondition {
- }
- public class AirconditionA extends Aircondition{
- public AirconditionA(){
- System.out.println("制造-->AirconditionA");
- }
- }
- public class AirconditionB extends Aircondition{
- public AirconditionB(){
- System.out.println("制造-->AirconditionB");
- }
- }
创建工厂类:
- //创建工厂的接口
- public interface AbstractFactory {
- //制造发动机
- public Engine createEngine();
- //制造空调
- public Aircondition createAircondition();
- }
- //为宝马320系列生产配件
- public class FactoryBMW320 implements AbstractFactory{
- @Override
- public Engine createEngine() {
- return new EngineA();
- }
- @Override
- public Aircondition createAircondition() {
- return new AirconditionA();
- }
- }
- //宝马523系列
- public class FactoryBMW523 implements AbstractFactory {
- @Override
- public Engine createEngine() {
- return new EngineB();
- }
- @Override
- public Aircondition createAircondition() {
- return new AirconditionB();
- }
- }
客户:
- public class Customer {
- public static void main(String[] args){
- //生产宝马320系列配件
- FactoryBMW320 factoryBMW320 = new FactoryBMW320();
- factoryBMW320.createEngine();
- factoryBMW320.createAircondition();
- //生产宝马523系列配件
- FactoryBMW523 factoryBMW523 = new FactoryBMW523();
- factoryBMW320.createEngine();
- factoryBMW320.createAircondition();
- }
- }
阅读全文
0 0
- IOC设计模式的理解
- 【设计模式】IOC模式
- IOC模式理解
- spring ,ioc ,dependency injection 的设计模式
- ioc以及Aop涉及到的设计模式
- 设计模式的理解
- 设计模式的理解
- 设计模式的理解
- 设计模式的理解
- 设计模式的理解
- 设计模式的理解
- 设计模式----IoC
- IOC设计模式C#
- 设计模式(8)--Ioc模式
- 设计模式--IOC(DI)与AOP思想涉及的模式
- 设计模式--IOC(DI)与AOP思想涉及的模式
- 一篇让你真正理解 Laravel IoC 模式的文章
- 我理解的设计模式
- 解决‘底层的图层经过transform:rotate转换后,覆盖住高图层’的问题
- 未来已来!阿里小蜜AI技术揭秘
- cocos2d-x 瓦片地图CCTMXTiledMap和图层类CCTMXLayer
- java模板引擎替换代码
- java中substring与substr的用法
- IOC设计模式的理解
- spring boot 集成mybatis
- Python3-Flask-微信公众号开发-3
- Monkey测试结果分析
- Swift 4.0 轮播图
- 有符号数与无符号数比较-详解
- Scikit-Learn Knowledge
- 封装了一个关于python操作fastDFS的类,方便调用
- 如何在linux中设置另一个ip服务器