设计模式
文章平均质量分 85
天狼1222
不是试图,而是切切实实去做,只想一味尝试的人终归一事无成
展开
-
装饰模式 – 半透明装饰模式
装饰模式 – 半透明装饰模式:目录I/O 应用源码:输入流 InputStream应用:读取txt文件:结果:Poi读取excel文件:读取excel代码:测试:结果:总结:在装饰模式的学习中,会出现一个透明装饰模式和半透明的装饰,是什么意思呢?透明装饰模式在透明装饰模式中要求客户端完全针对抽象编程,装饰模式的透明性要求客户端程序不应该将对象声明为具体构件类型或具体装饰类型,而应该全部声明为抽象构件类型。对客户端而言,具体构件类和具体装...原创 2021-02-28 16:43:35 · 529 阅读 · 0 评论 -
代理模式 – cglib代理
代理模式 – cglib代理目录cglib代理例子-常规代码:问候 Greet问候实现 GreetIml商店 Shop商店实现 ShopImplcglib代理 CGLibProxy测试:,结果:例子-单例模式代码:cglli代理 CGLibProxySingle测试:结果:总结:cglib代理在使用的是静态代理和动态代理都需要目标对象是一个实现了接口的目标对象,当目标对象可能只是一个单独的对象,并没有实现任何的接口,那如何进...原创 2021-02-28 11:26:32 · 2073 阅读 · 2 评论 -
代理模式 – 动态代理
代理模式 – 动态代理动态代理在代理模式中,使用的是静态代理的方式,那如何进行动态代理?动态代理是什么? 在程序运行时由Java反射机制动态生成。如何实现呢? 在Java中要想实现动态代理机制,需要java.lang.reflect.InvocationHandler接口和 java.lang.reflect.Proxy 类的支持例子-常规代码:问候 Greetpublic interface Greet {...原创 2021-02-28 11:01:45 · 456 阅读 · 2 评论 -
代理模式(Prototype Pattern)– 设计模式之结构型模式
代理模式(Prototype Pattern)– 设计模式之结构型模式:代理模式(Prototype Pattern)定义:Provide a surrogate or placeholder for another object to control access to it.为其它对象提供一种代理以控制对这个对象的访问类图代理模式通用类图: 保护代理:根据访问权限决定用户是否访问对象的代理。例子-美食店: 过程:在生活中,有一些特色...原创 2021-02-27 22:41:32 · 429 阅读 · 0 评论 -
单例模式(Singleton Pattern) – 设计模式之创建型模式
单例模式(Singleton Pattern) – 设计模式之创建型模式:目录单例模式(Singleton Pattern)类图单例实现方式:饿汉:懒汉:双重校验锁:静态内部类:比较推荐枚举:推荐的方式分析总结:使用场景单例模式(Singleton Pattern)定义:Ensure a class has only one instance, and provide a global point of access to it.确保一个类只有一.原创 2021-02-27 15:38:24 · 379 阅读 · 0 评论 -
原型模式(Prototype Pattern) – 设计模式之创建型模式
原型模式(Prototype Pattern) – 设计模式之创建型模式:目录原型模式(Prototype Pattern)知识点:类图例子-形状:过程:代码:形状 Shape 实现 Cloneable测试:结果:总结:使用场景原型模式(Prototype Pattern)定义:Specify the kinds of objects to create using a prototypical instance, and create new o..原创 2021-02-24 15:01:17 · 178 阅读 · 0 评论 -
适配器模式(Adapter Pattern) – 设计模式之结构型模式
适配器模式(Adapter Pattern) – 设计模式之结构型模式:适配器模式(Adapter Pattern)定义: Convert the interface of a class info another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces. (将一个类的接口变换成客户端所期待的.原创 2021-02-23 09:18:28 · 514 阅读 · 0 评论 -
享元模式(Flyweight Pattern) – 设计模式之结构型模式
享元模式(Flyweight Pattern) – 设计模式之结构型模式:享元模式(Flyweight Pattern)定义: Use sharing to support large numbers of fined-grained objects efficiently.运用共享技术有效地支持大量细粒度的对象要求细粒度对象,那么不可避免地使得对象数量多且性质相近,那我们就将这些对象的信息分为两个部分:内部状态(intrinsic)与外部状态(extrinsic)。1 内部状态.原创 2021-02-22 20:48:04 · 329 阅读 · 0 评论 -
装饰模式(Decorator Pattern) – 设计模式之结构型模式
装饰模式(Decorator Pattern) – 设计模式之结构型模式:装饰模式(Decorator Pattern)定义: Attach additional responsibilities to an object dynamically keeping the same interface. Decoratiors provide a flexible alternative to subclassing for extending functionality.动态地给一个对象添.原创 2021-02-22 15:56:09 · 397 阅读 · 0 评论 -
迭代模式(Iterator Pattern) – 设计模式之行为模式
迭代模式(Iterator Pattern) – 设计模式之行为模式:目录迭代模式(Iterator Pattern)类图例子-遍历:过程:类图:代码:抽象迭代器 Iterator具体迭代器 ConcreteIterator抽象容器 Aggregate具体容器 ConcreteAggregate测试:结果:总结:使用场景迭代模式(Iterator Pattern)定义: Provide a way to access the eleme..原创 2021-02-22 09:36:46 · 334 阅读 · 0 评论 -
解释器模式(Interpreter Pattern) – 设计模式之行为模式
解释器模式(Interpreter Pattern) – 设计模式之行为模式:解释器模式(Interpreter Pattern)定义: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.给定一个语言,定义它的文法的一种表示,并定义一个解..原创 2021-02-21 21:16:32 · 350 阅读 · 0 评论 -
命令模式(Command Pattern) 实例
命令模式(Command Pattern) 实例:在上一个例子命令模式中,并没有出现类图中Receiver的角色,现在风扇要换挡,电视要换台,加减音量。这时候该怎么做?思考: 电灯只有两个动作: 开和关风扇有四个动作: 开、关、加挡和减挡电视有六个动作: 开、关、加台、减台、加音量和减音量把命令分成三种,然后加入一个Receiver 去接三种的命令例子-遥控器: 类图: 代码:接口 Command public interf...原创 2021-02-21 10:36:16 · 1549 阅读 · 1 评论 -
命令模式(Command Pattern) – 设计模式之行为模式
命令模式(Command Pattern) – 设计模式之行为模式:目录命令模式(Command Pattern)类图例子-开关:过程:类图:代码:接口 SwitchCommand灯泡 Bulb电风扇 ElectricFan电视 Television调用 SwitchInvoke测试:结果:分析总结:使用场景命令模式(Command Pattern)定义: Encapsulate a request as an object, th原创 2021-02-20 09:58:50 · 506 阅读 · 0 评论 -
Java 正则表达式的用法和一些具体实例
Java 正则表达式的用法和具体实例目录正则表达式常用符号:Java 中正常表达式的应用:实例1:要求:思考:代码:结果:分析:总结:正则表达式常用符号: 字符 说明 ^ 匹配输入字符串的开始位置。要匹配 "^" 字符本身,请使用 "\^" $ 匹配输入字符串的结尾位置。要匹配 "$" 字符本身,请使用 "\$" ( ..原创 2021-01-12 16:59:25 · 621 阅读 · 0 评论 -
责任链模式(Chain of Responsibility Pattern) – 设计模式之行为模式
状态模式(Chain of Responsibility Pattern) – 设计模式之行为模式:状态模式(Chain of Responsibility Pattern)定义:Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the .原创 2021-02-18 16:19:43 · 138 阅读 · 0 评论 -
状态模式(State Pattern) – 设计模式之行为模式
状态模式(State Pattern) – 设计模式之行为模式:状态模式(State Pattern)定义: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类。 主要解决的是当控制一个对象状态转换的条件表达式过于复杂时的情况,把状态的判...原创 2021-02-18 10:12:03 · 541 阅读 · 0 评论 -
观察者模式(Observe Pattern) – 设计模式之行为模式
观察者模式(Observe Pattern) – 设计模式之行为模式:观察者模式(Observe Pattern)定义:Define a one-to-many dependency between object changes state, all its dependents are notified and updated automatically.观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时,会通知所有的观察者对..原创 2021-02-10 09:22:54 · 578 阅读 · 0 评论 -
备忘录模式(Memento Pattern) – 设计模式之行为模式
备忘录模式(Memento Pattern) – 设计模式之行为模式:目录备忘录模式(Memento Pattern)类图例子:过程:类图:代码:游戏:Game游戏备份:GameHistory玩家:Player测试:结果:总结:使用场景备忘录模式(Memento Pattern)定义: Without violating encapsulation, capture and externalize an object’s internal.原创 2021-02-09 14:43:42 · 330 阅读 · 0 评论 -
中介者模式(Mediator Pattern) – 设计模式之行为型模式
中介者模式(Mediator Pattern) – 设计模式之行为型模式:目录中介者模式(Mediator Pattern)类图例子:过程:代码:海贼团:PirateCrews测试:优化:过程:类图:代码:海贼团(抽象同事类):PirateCrew消息中间类(抽象中介者):MessageMediator消息中间类实现(通用中介者):MessageMediatorImpl黑胡子海贼团(具体同事类):Blackbeard红发海贼团(具体同事类)原创 2021-02-09 09:12:21 · 474 阅读 · 0 评论 -
java 设计模式 深入理解
java 设计模式 深入理解在学习设计模式的时候,以前学习了下总以为理解了,但是在实际工作中基本上用不起来。在学习拆书后,想到用讲的方式去学习和思考的时候,要想讲清楚,就要深入理解其中的原理。在重新整理和写下来的过程中,感觉基本上是掌握了,在工作中遇到的时候,也慢慢也去考虑了。教是最好的学。在整理写的时候,也会有不同的思考。创建型抽象工厂模式工厂方法模式建造者模式原型模式-X单态模式-X结构型适配器模式-X桥接模式组合模式外观模式装饰者模式-X享...原创 2024-03-21 12:48:15 · 1336 阅读 · 2 评论 -
访问者模式(Visitor Pattern) – 设计模式之行为型模式
访问者模式(Visitor Pattern) – 设计模式之行为型模式:目录访问者模式(Visitor Pattern)例子1:过程:类图:代码:药品:Medicine访问接口:Acceptable感冒药:Coldrex消炎药:InflammatoryDrugs访问者接口: IVisitor收营员: Cashier药剂师:Pharmacists药单子:MedicineList测试:结果:双分派:概念例子EastSubEast原创 2021-02-07 11:06:59 · 634 阅读 · 0 评论 -
外观模式(Facade Pattern) – 设计模式之结构型模式
外观模式(Facade Pattern) – 设计模式之结构型模式:目录外观模式(Facade Pattern)类图例子1:过程:类图:代码:订酒店:Hotel订飞机:Airport接送: Charffeur订景点: TouristSpot接待外观:ReceptorFacade测试:结果:总结:使用场景外观模式(Facade Pattern)定义: Provide a unified interface to a set of i.原创 2021-02-06 10:38:43 · 319 阅读 · 0 评论 -
组合模式(Bridge Pattern) – 设计模式之结构型模式
组合模式(Bridge Pattern) – 设计模式之结构型模式:目录组合模式(Component Pattern)类图例子1:过程:类图:代码:抽象组件:PlayerComposite球员:BasketPlayer球队: PlayerComposite联盟: BasketLeager测试球员测试:结果:球队测试:结果:总结:组合模式(Component Pattern...原创 2021-02-05 16:58:14 · 425 阅读 · 0 评论 -
桥梁模式(Bridge Pattern) – 设计模式之结构型模式
桥梁模式(Bridge Pattern) – 设计模式之结构型模式:目录桥梁模式(Bridge Pattern)定义:类图例子1:过程:类图:颜色:颜色类:Color蓝色:Blue橘色: Orange粉红色: Pink形状形状类:圆形:Circle矩形:Rectangle三角形:Triangle测试:结果:优化例子1合成/聚合复用原则(CARP):类图:形状形状接口:Shape圆形:Circle矩形.原创 2021-01-31 15:14:47 · 672 阅读 · 0 评论 -
抽象模式(Abstract Factory Pattern) – 设计模式之创建模式
抽象模式(Abstract Factory Pattern) – 设计模式之创建模式:目录抽象工厂模式定义:A,类图例子:类图:抽象工厂类:形状工厂:形状:Shape圆形: Circle三角形: Triangle矩形: Rectangle形状枚举类: ShapeTypeEnum形状工厂类: ShapeFactory测试类;颜色工厂:形状:Color蓝色:Blue橘色: Orange粉红色:Pink颜色枚举类: ShapeTy原创 2021-01-30 11:52:09 · 655 阅读 · 0 评论 -
工厂模式(Factory Pattern) – 设计模式之创建模式
工厂模式(Factory Pattern) – 设计模式之创建模式定义:定义: Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.定义一个创建对象的接口,让其子类自己决定实例化哪一个工厂类,工厂模式使其创建过程延迟到子类...原创 2021-01-29 20:12:35 · 527 阅读 · 0 评论 -
模板模式(Template Pattern) – 设计模式之行为模式
模板模式(Template Pattern) – 设计模式之行为模式:定义:定义: Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Mothod lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.当我.原创 2021-01-27 15:11:28 · 548 阅读 · 0 评论 -
建造者模式 – 设计模式之创建模式
建造者模式 – 设计模式之创建模式:目录定义:类图:StringBuilder:应用场景一:多个参数查询拼接订单查询参数类:OrderParam订单查询参数测试类: OrderParamBuilderTest请求参数拼接 OrderController总结:定义: Separate the construction of a complex object from its representation so that the same construc...原创 2021-01-25 17:07:12 · 319 阅读 · 0 评论
分享