- Java EE 8 Design Patterns and Best Practices
- Rhuan Rocha Jo?o Purifica??o
- 429字
- 2021-07-23 16:54:49
Explaining the Gang of Four design patterns
The Gang of Four (GoF) design patterns are 23 patterns that are classified as creational patterns, structural patterns, and behavioral patterns. The creational patterns control the creation and initialization of the object and class selection; the structural patterns define the relationship between classes and objects, and the behavioral patterns control the communication and interaction between objects. As well as this, the GoF design patterns have two types of scope which define the focus of solutions. These scopes are object scope, which resolves problems about object relations, and class scope, which resolves problems about class relations.
The object scope works with composition and the behavior changes are done in a runtime. Thus, the object can have a dynamic behavior. The class scope works with inheritance and its behavior is static-fixed at compile-time way. Then, to change the behavior of a class-scope pattern, we need to change the class and recompile.
Patterns classified as class scope solve problems about the relationship between classes and are static (fixed at compile time and cannot be changed once compiled). However, patterns classified under the object scope solve problems about the relationship between objects and can be changed at runtime.
The following diagram shows us the three classifications, as well as their patterns and scope:

In the preceding diagram, we can see the Factory Method pattern on the Class section and the Abstract Factory pattern on the Object section. This occurs because the Factory Method works with inheritance and the abstract method pattern works with composition. Then, the Factory Method is static-fixed at compile time and cannot be changed after compilation. However, the Abstract Factory is dynamic and can be changed at runtime.
GoF design patterns are generally described using a graphical notation such as a use case diagram, and an example of the implementation's code. The used notation must be able to describe the classes and objects as well as the relationship between these classes and objects.
The pattern's name is an important part of the design patterns. This is because it is what the developer uses to quickly identify the problem related to the pattern and to understand how the pattern will solve it. The name of the pattern must be brief and refer to the problem and its solution.
A design pattern is a great tool for designing software development, but its use needs to be analyzed to determine if the design pattern is really required in order to solve the problem.
- SharePoint 2013 應用開發實戰
- Linux網絡內核分析與開發
- Instant Optimizing Embedded Systems using Busybox
- 直播系統開發:基于Nginx與Nginx-rtmp-module
- Linux系統安全基礎:二進制代碼安全性分析基礎與實踐
- AutoCAD 2014中文版從入門到精通
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理
- Kali Linux高級滲透測試
- Linux設備驅動開發
- 統信UOS應用開發進階教程
- bash shell腳本編程經典實例(第2版)
- Linux集群之美
- Agile IT Security Implementation Methodology
- Mastering Sass
- 大規模Linux集群架構最佳實踐:如何管理上千臺服務器