软件体系架构方面英文文章翻译----架构风格、架构模式和设计模式的区别

Difference Between Architectural Style, Architectural Patterns and Design Patterns

02 Dec, 2022

Many software professionals think that architectural styles and patterns are the same. Sadly, some of the software developers don’t understand the difference between architectural patterns and design patterns. In this article, we’re going to summarize the differences between them.

According to MSDN, architectural styles and patterns are the same things. But how can it be? The word style means: “a manner of doing something” while a pattern means: “a repeated decorative design”. However, these definitions show two different things. In software engineering, the terminology must be more clear and describe something specific. So, what’s the difference between the terminologies and how can we differentiate between them?

Architectural Style

The architectural style shows how do we organize our code, or how the system will look like from 10000 feet helicopter view to show the highest level of abstraction of our system design. Furthermore, when building the architectural style of our system we focus on layers and modules and how they are communicating with each other. There are different types of architectural styles, and moreover, we can mix them and produce a hybrid style that consists of a mix between two and even more architectural styles. Below is a list of architectural styles and examples for each category:

  • Structure architectural styles: such as layered, pipes and filters and component-based styles.
  • Messaging styles: such as Implicit invocation, asynchronous messaging and publish-subscribe style.
  • Distributed systems: such as service-oriented, peer to peer style, object request broker, and cloud computing styles.
  • Shared memory styles: such as role-based, blackboard, database-centric styles.
  • Adaptive system styles: such as microkernel style, reflection, domain-specific language styles.

Architectural Patterns

The architectural pattern shows how a solution can be used to solve a reoccurring problem. In another word, it reflects how a code or components interact with each other. Moreover, the architectural pattern is describing the architectural style of our system and provides solutions for the issues in our architectural style. Personally, I prefer to define architectural patterns as a way to implement our architectural style. For example: how to separate the UI of the data module in our architectural style? How to integrate a third-party component with our system? how many tires will we have in our client-server architecture? Examples of architectural patterns are microservices, message bus, service requester/ consumer, MVC, MVVM, microkernel, n-tier, domain-driven design, and presentation-abstraction-control.

Design Patterns

Design patterns are accumulative best practices and experiences that software professionals used over the years to solve the general problem by – trial and error – they faced during software development. The Gang of Four (GOF, refers to Eric Gamma, Richard Helm, Ralf Johnson, and John Vlissides) wrote a book in 1994 titled with “Design Pattern – Elements of reusable object-oriented software” in which they suggested that design patterns are based on two main principles of object-oriented design:

  • Develop to an interface, not to an implementation.
  • Favor object composition over inheritance.

Also, they presented that the design patterns set contains 23 patterns and categorized into three main sets:

1. Creational design patterns:

Provide a way to create objects while hiding the creation logic. Thus, the object creation is to be done without instantiating objects directly with the “New” keyword to gives the flexibility to decide which objects need to be created for a given use case. The creational design patterns are:

  • Abstract factory pattern: provide an interface to create objects without specifying the classes.
  • Singleton pattern: provide only a single instance of the calls and global access to this instance.
  • Builder Pattern: Separate the construction from representation and allows the same construction to create multiple representations.
  • Prototype pattern: creating duplicate without affecting the performance and memory. So the duplicate object is built from the skeleton of an existing object.

2. Structural patterns:

Concerned with class and object composition. The Structural design patterns are:

  • Adapter pattern: it works as a bridge between two incompatible interfaces and combines their capabilities.
  • Bridge pattern: provide a way to decouple the abstraction from its implementation.
  • Filter pattern: Also known as criteria pattern, it provides a way to filter a set of objects using different criteria and chaining them in a decoupled way through logical operations.
  • Composite pattern: provide a way to treat a group of objects in a similar way as a single object. It composes objects in term of a tree structure to represent part as well as a whole hierarchy
  • Decorator pattern: allows adding new functionality to an existing object without altering its structure.
  • Façade pattern: provide a unified interface to a set of interfaces.it hides the complexities of the system and provides an interface to the client using which the client can access the system.
  • Flyweight pattern: reduce the number of objects created and to decrease memory footprint and increase performance. It helps in reusing already existing similar kind objects by storing them and creates a new object when no matching object is found.
  • Proxy pattern: provides a place holder to another object to control access to it. The object has an original object to interface its functionality to the outer world.

3. Behavioral patterns:

Behavioral patterns are concerned with communications between objects. The following is the list of behavioral patterns:

  • Responsibility pattern: creates a chain of receiver objects for a request. This pattern decouples the sender and receiver of a request based on the type of request.
  • Command pattern: it’s a data-driven pattern in which A request is wrapped under an object as command and passed to an invoker object.
  • Interpreter pattern: provides a way to evaluate language grammar or expression. It involves implementing an expression interface that tells to interpret a particular context. This pattern is used in SQL parsing, symbol processing engine, etc.
  • Iterator pattern: provides a way to access the elements of a collection object in a sequential manner without any need to know its underlying representation.
  • Mediator pattern: used to reduce communication complexity between multiple objects or classes. It provides a mediator class that normally handles all the communications between different classes and supports easy maintenance of the code by loose coupling.
  • Memento pattern: used to restore the state of an object to a previous state.
  • Observer pattern: used when there is a one-to-many relationship between objects such as if one object is modified, its dependent objects are to be notified automatically.
  • State pattern: is used to change the class behavior based on its state.
  • Null object pattern: helps to avoid null references by having a default object.
  • Strategy pattern: provides a way to change class behavior or its algorithm at run time.
  • Template pattern: an abstract class exposes defined way(s)/template(s) to execute its methods. Its subclasses can override the method implementation as per need but the invocation is to be in the same way as defined by an abstract class.
  • Visitor pattern: used to change the executing algorithm of an element class.

There are two more subsets of design pattern can be added to the 3 categories of design pattern:

  • J2EE patterns: patterns are specifically concerned with the presentation tier. These patterns are identified by Sun Java Center.
  • Concurrency patterns: such as: balking, join, lock and Thread pool patterns

The bottom line:

The architectural style is a 10000-helicopter view of the system. It shows the system design at the highest level of abstraction. It also shows the high-level module of the application and how these modules are interacting. On the other hand, architectural patterns have a huge impact on system implementation horizontally and vertically. Finally, the design patterns are used to solve localized issues during the implementation of the software. Also, it has a lower impact on the code than the architectural patterns since the design pattern is more concerned with a specific portion of code implementation such as initializing objects and communication between objects.


架构风格、架构模式和设计模式之间的区别

02 十二月, 2022

许多软件专业人士认为,架构风格和模式是一样的。可悲的是,一些软件开发人员并不了解架构模式和设计模式之间的区别。在这篇文章中,我们将总结它们之间的区别。

根据MSDN的说法,架构风格和模式是同样的东西。但这怎么可能呢?风格这个词的意思是。"一种做事的方式 ",而模式的意思是:"一种重复的装饰设计"。"一种重复的装饰性设计 "**。然而,这些定义显示了两种不同的东西。在软件工程中,术语必须更加明确,并描述具体的东西。那么,这些术语之间有什么区别,我们如何区分它们?

架构风格

架构风格显示了我们如何组织我们的代码,或者说从10000英尺的直升机上看,系统会是什么样子,以显示我们系统设计的最高抽象水平。此外,在构建我们系统的架构风格时,我们关注的是层和模块,以及它们之间是如何交流的。有不同类型的架构风格,此外,我们可以将它们混合起来,产生一种混合风格,由两种甚至更多的架构风格混合而成。以下是建筑风格的清单和每一类的例子。

  • 结构架构风格:如分层、管道和过滤器以及基于组件的风格。
  • 信息传递风格:**如隐式调用、异步信息传递和发布-订阅风格。
  • 分布式系统:**如面向服务、点对点风格、对象请求代理和云计算风格。
  • 共享内存风格:如基于角色、黑板、以数据库为中心的风格。
  • 自适应系统风格:如微内核风格、反射、特定领域语言风格。

架构模式

架构模式显示了一个解决方案如何被用来解决一个重复出现的问题。换句话说,它反映了一个代码或组件如何相互作用。此外,架构模式还描述了我们系统的架构风格,并为我们架构风格中的问题提供解决方案。就我个人而言,我更愿意将架构模式定义为实现我们的架构风格的一种方式。例如:如何在我们的架构风格中分离数据模块的UI?如何将第三方组件与我们的系统集成?在我们的客户-服务器架构中,我们将有多少个轮胎?架构模式的例子有:微服务、消息总线、服务请求者/消费者、MVC、MVVM、微内核、n-tier、领域驱动设计和表现形式-抽象-控制。

设计模式

设计模式是软件专业人员多年来用来解决他们在软件开发过程中面临的一般问题的最佳实践和经验的积累--试验和错误。四人帮(GOF,指Eric Gamma、Richard Helm、Ralf Johnson和John Vlissides)在1994年写了一本名为《设计模式--可重用的面向对象软件的要素》的书,其中他们提出,设计模式是基于面向对象设计的两个主要原则。

  • 对接口进行开发,而不是对实现进行开发。
  • 赞成对象组合而不是继承。

此外,他们还提出了设计模式集包含23个模式,并被分为三个主要部分。

1. 创造性设计模式:

提供一种创建对象的方法,同时隐藏创建逻辑。因此,创建对象时不需要直接使用 "New "关键字来实例化对象,这样就可以灵活地决定哪些对象需要在特定的使用情况下创建。创造性的设计模式是。

  • 抽象工厂模式:提供一个接口来创建对象,而无需指定类。
  • Singleton模式:只提供一个调用的单一实例,并对该实例进行全局访问。
  • Builder模式:将构造与表示分离,允许同一构造创建多个表示。
  • 原型模式:在不影响性能和内存的情况下创建重复的对象。因此,复制的对象是由现有对象的骨架建立的。

2. 结构模式:

关注类和对象的构成。结构性设计模式有。

  • 适配器模式:它作为两个不兼容的接口之间的桥梁,结合它们的能力。
  • 桥梁模式:提供了一种将抽象与实现解耦的方法。
  • 过滤模式:也被称为标准模式,它提供了一种使用不同标准过滤一组对象的方法,并通过逻辑操作以解耦的方式将其链起来。
  • 复合模式:提供了一种方法,以类似于单个对象的方式处理一组对象。它以树状结构的方式组合对象,以表示部分和整体的层次结构。
  • 装饰者模式:**允许在不改变其结构的情况下为现有对象添加新的功能。
  • Façade模式:为一组接口提供了一个统一的接口。它隐藏了系统的复杂性,并为客户提供了一个接口,客户可以使用它来访问系统。
  • 轻量级模式:**减少创建对象的数量,减少内存占用并提高性能。它通过存储已有的类似对象来帮助重用它们,并在没有找到匹配对象时创建一个新的对象。
  • 代理模式:为另一个对象提供了一个放置者来控制对它的访问。该对象有一个原始对象,将其功能与外部世界对接。

3. 行为模式:

行为模式涉及到对象之间的通信。以下是行为模式的列表。

  • 响应性模式:为一个请求创建一个接收器对象链。这种模式根据请求的类型将请求的发送方和接收方解耦。
  • 命令模式:**是一个数据驱动的模式,在这个模式中,一个请求被包裹在一个对象下作为命令,并传递给一个调用者对象。
  • 解释器模式:**提供了一种评估语言语法或表达式的方法。它涉及到实现一个表达式接口,告诉人们要解释一个特定的上下文。这种模式被用于SQL解析、符号处理引擎等。
  • 迭代器模式:提供了一种以顺序方式访问集合对象的元素的方法,而不需要知道其底层表示。
  • 调解器模式:用于减少多个对象或类之间的通信复杂性。它提供了一个中介类,通常处理不同类之间的所有通信,并通过松散耦合支持对代码的轻松维护。
  • 记忆模式:用于将一个对象的状态恢复到之前的状态。
  • 观察者模式:**用于对象之间存在一对多的关系时,例如,如果一个对象被修改,其依赖对象将被自动通知。
  • 状态模式:**用于根据类的状态来改变其行为。
  • 空对象模式:**通过设置一个默认对象来帮助避免空引用。
  • 策略模式:提供了一种在运行时改变类行为或其算法的方法。
  • 模板模式:**一个抽象类公开了执行其方法的定义方式/模板。它的子类可以根据需要覆盖方法的实现,但是调用的方式必须与抽象类定义的方式相同。
  • 访问者模式:**用于改变元素类的执行算法。

在这三类设计模式中,还有两个设计模式的子集可以被加入。

  • J2EE模式:模式是专门关注表现层的。这些模式是由Sun Java中心确定的。
  • 并发模式:如:balking、join、lock和Thread pool模式。

底线:

架构风格是对系统的10000个螺旋桨视图。它显示了最高级别的抽象的系统设计。它还显示了应用程序的高级模块以及这些模块是如何交互的。另一方面,架构模式在水平和垂直方向上对系统的实现有巨大影响。最后,设计模式被用来解决软件实现过程中的局部问题。而且,它对代码的影响比架构模式要小,因为设计模式更关注代码实现的特定部分,如初始化对象和对象之间的通信。

来自GeeksForGeeks

posted @ 2023-03-02 19:46  zhuangzhongxu  阅读(59)  评论(0编辑  收藏  举报