首页 > 其他分享 >[Design Pattern] Intro: Three groups of patterns

[Design Pattern] Intro: Three groups of patterns

时间:2024-01-23 15:27:14浏览次数:21  
标签:Pattern into object request Three patterns Lets objects its

Creational patterns provide object creation mechanisms that increase flexibility and reuse of existing code.

  • Factory method: Provides an interface for creating objects in a superclass, but allow subclass to alter the type of objects that will be created.
  • Abstract Factory: Lets you produce families of related objects without specifying their concrete classes.
  • Builder: Lets you construct complex objects step by step. The patterns allows you to produce different types and representations of an object using the same construction code.
  • Prototype: Lets you copy existing objects without making your code dependent on their classes.
  • Singleton: Lets you ensure that a class has only one instance, while providing a global access point to this instance.

Structural patterns explain how to asssemble objects and classes into larger structures, while keeping these structures flexible and efficient.

  • Adapter: Allow objects with incompatible interfaces to collaborate.
  • Bridge: Lets you split a large class or a set of closely related classes into two separate hierarchies - abstraction and implementation - which can be developed independently of each other.
  • Composite: Let you compose objects into tree structures and then work with those structures as if they were individual object.
  • Decorator: Lets you attach new behaviors to objects by placing these objects inside speical wrapper objects that contain the behaviors.
  • Facade: Provides a simplified interface to library, a framework, or any other ocmplex set of classes.
  • Flyweight: Let you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object.
  • Proxy: Lets you provide a substitute or placeholder for another object. A proxy controls acces to the original object, allowing you to perform something either before or after the request gets through to the original object.

Behavioral patterns take care of effective communication and assignment of reponsibilities between objects.

  • Chain of Responsibility: Lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.
  • Command: Turns a request into a stand-alone object that contains all information about the request. This transformation lets you pass request as a method arguments, delay or queue a request's execution, and support undoable operations.
  • Iterator: Lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc).
  • Mediator: Lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.
  • Memento: Lets you save and restore the previous state of an objet without revealing the details of its implementation.
  • Observer: Lets you define subscription mechanism to notify multiple objects about any events that happen to the object they're observing.
  • State: Lets an object alter its behavior when its internal state changes. It appears as if the obejct changed its class.
  • Strategy: Lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.
  • Template Method: Defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.
  • Visitor: Lets you separate algorithms from the object on which they opearte.

标签:Pattern,into,object,request,Three,patterns,Lets,objects,its
From: https://www.cnblogs.com/Answer1215/p/17982543

相关文章

  • CF1914D Three Activities
    题目大意给定三个数组\(a,b,c\)找三个互不相同的整数\(i,j,k\)使得\(a_i+b_j+c_k\)的值最大.思路首先想到的当然是枚举\(i,j,k\)然后找到最大值,但这种方法的时间复杂度是\(O(n^3)\),显然会喜提\(TLE\).当然由瞪眼法可知,因为我们只需要找到\(a_i+b_j......
  • 【Leetcode1949. 坚定的友谊】使用MySQL在无向图中寻找{"CompleteTripartite", {1, 1,
    目录题目地址思路代码MySQL代码逐行翻译为Pandas代码等效Cypher查询(未验证)题目地址https://leetcode.cn/problems/strong-friendship/思路就是在无向图中寻找这个pattern:(*Mathematica*)GraphData[{"CompleteTripartite",{1,1,3}}]SQL写还是比较麻烦。更加复杂的查询还是......
  • BZOJ1717 Milk Patterns 产奶的模式 (二分+后缀数组+height数组)
    发现这样起标题更能引流(ylg实锤了)题意给定一个长度为\(n\)的数组\(a\),求在\(a\)中出现了至少\(k\)次的最长子串的长度。解法考虑将一个子串拆成两个后缀,即\([l,r]=[l,n]-[r,n]\),发现一个长度为\(x\)的子串\(t\)在\(i,j\)两个位置出现过当且仅当后缀\(i,j\)有......
  • GIS融合之路(二)CesiumJS和ThreeJS深度缓冲区整合
    在这篇文章开始前再次重申一下,山海鲸并没有使用ThreeJS引擎。但由于ThreeJS引擎使用广泛,下文中直接用ThreeJS同CesiumJS的整合方案代替山海鲸中3D引擎和CesiumJS整合。系列传送门:山海鲸可视化:GIS融合之路(一)技术选型CesiumJS/loaders.gl/iTowns?文章开始之前大家可以看下这个视......
  • 【Leetcode1949. 坚定的友谊】使用MySQL在无向图中寻找{"CompleteTripartite", {1, 1,
    目录题目地址思路代码MySQL代码等效Cypher查询(未验证)题目地址https://leetcode.cn/problems/strong-friendship/思路就是在无向图中寻找这个pattern:(*Mathematica*)GraphData[{"CompleteTripartite",{1,1,3}}]SQL写还是比较麻烦。更加复杂的查询还是建议把数据迁......
  • 一行代码解决Three.js中只能在一侧看到物体的问题
    项目场景:  因为该项目比较复杂庞大,在此就简单介绍一下:  通过Three.js创建若干个物体进行了组装,从而形成了一个类似眼球模拟模型的项目,用户可以通过拖动鼠标来达到控制视角(摄像机)的目的,以此来观察整个眼球状态。Image1Three.js眼球模型  注:下面所说的正视为从红线正轴......
  • [LeetCode] 1363. Largest Multiple of Three 形成三的最大倍数
    Givenanarrayofdigits digits,return thelargestmultipleof three thatcanbeformedbyconcatenatingsomeofthegivendigitsin anyorder.Ifthereisnoanswerreturnanemptystring.Sincetheanswermaynotfitinanintegerdatatype,returnt......
  • Python实现软件设计模式8:桥接模式 Bridge Pattern
    动机将抽象部分与实现部分分离,使他们都可以独立地变化。用抽象关联取代传统的多层继承。将类之间的静态继承关系转换为动态的对象组合关系。上图展示的软件系统中存在两个独立地变化维度,分别是抽象类(Abstraction)和实现类(Implementor),它俩都是接口、都分别可以独立地扩展出多......
  • Python实现软件设计模式7:适配器模式 Adapter Pattern
    动机有两个不存在直接继承或关联关系的类A、B,A希望能利用到B类中某个已存在的、功能完善的方法,而不再去具体实现A的接口源码;适配器模式使接口不兼容的那些类可以一起工作。主要角色目标类Target抽象接口类适配者Adaptee适配器Adapter具体实现接口客户端C......
  • Three.js——十五、Box3、相机动画、lookAt()视线方向、管道漫游案例、OrbitControls
    正投影相机正投影相机和透视相机的区别如果都以高处俯视去看整个场景,正投影相机就类似于2d的可视化的效果,透视相机就类似于人眼观察效果调整left,right,top,bottom范围大小如果你想整体预览全部立方体,就需要调整相机的渲染范围,比如设置上下左右的范围。使用场景:正投影可以......