ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

design patterns of refactoring guru

2022-02-20 11:33:42  阅读:360  来源: 互联网

标签:object how guru patterns design Design 设计模式


What's a design pattern?

https://refactoring.guru/design-patterns/what-is-pattern

设计模式应对软件设计过程中经常出现的问题。

Design patterns are typical solutions to commonly occurring problems in software design. They are like pre-made blueprints that you can customize to solve a recurring design problem in your code.

History of patterns

对于这些经常出现的问题,形成了常用的解决方法,

这些问题和方法在很多项目中不定地重复出现, 人们就给这些解决方法名称。

 

设计模式起源于建筑领域。

然后被吸到软件开发领域。

Who invented patterns? That’s a good, but not a very accurate, question. Design patterns aren’t obscure, sophisticated concepts—quite the opposite. Patterns are typical solutions to common problems in object-oriented design. When a solution gets repeated over and over in various projects, someone eventually puts a name to it and describes the solution in detail. That’s basically how a pattern gets discovered.

The concept of patterns was first described by Christopher Alexander in A Pattern Language: Towns, Buildings, Construction. The book describes a “language” for designing the urban environment. The units of this language are patterns. They may describe how high windows should be, how many levels a building should have, how large green areas in a neighborhood are supposed to be, and so on.

The idea was picked up by four authors: Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm. In 1994, they published Design Patterns: Elements of Reusable Object-Oriented Software, in which they applied the concept of design patterns to programming. The book featured 23 patterns solving various problems of object-oriented design and became a best-seller very quickly. Due to its lengthy name, people started to call it “the book by the gang of four” which was soon shortened to simply “the GoF book”.

Since then, dozens of other object-oriented patterns have been discovered. The “pattern approach” became very popular in other programming fields, so lots of other patterns now exist outside of object-oriented design as well.

 

Why should I learn patterns?

设计模式是久经考验的成功方案,可以为我们提供解决思路。

设计模式是一种流行的设计语言, 软件领域的工作人员经常使用这些语言来沟通。

 

The truth is that you might manage to work as a programmer for many years without knowing about a single pattern. A lot of people do just that. Even in that case, though, you might be implementing some patterns without even knowing it. So why would you spend time learning them?

  • Design patterns are a toolkit of tried and tested solutions to common problems in software design. Even if you never encounter these problems, knowing patterns is still useful because it teaches you how to solve all sorts of problems using principles of object-oriented design.

  • Design patterns define a common language that you and your teammates can use to communicate more efficiently. You can say, “Oh, just use a Singleton for that,” and everyone will understand the idea behind your suggestion. No need to explain what a singleton is if you know the pattern and its name.

 

Classification of patterns

设计模式有高层和底层之分。

底层的模式被称为idioms, 经常只应用于一种编程语言。

高层的模式称为架构模式, 用于设计整个应用的架构。

不管高层和底层的差别, 设计模式还是可以被分为如下三类:

  • 创建者模式 -- 关注对象的创建,增加灵活性和复用性。
  • 结构模式 -- 关注对象和类的组装成更大的结构, 保持结构的灵活性和效率。
  • 行为模式 -- 关注对象之间的有效通信 和 责任分配。

Design patterns differ by their complexity, level of detail and scale of applicability to the entire system being designed. I like the analogy to road construction: you can make an intersection safer by either installing some traffic lights or building an entire multi-level interchange with underground passages for pedestrians.

The most basic and low-level patterns are often called idioms. They usually apply only to a single programming language.

The most universal and high-level patterns are architectural patterns. Developers can implement these patterns in virtually any language. Unlike other patterns, they can be used to design the architecture of an entire application.

In addition, all patterns can be categorized by their intent, or purpose. This book covers three main groups of patterns:

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

  • Structural patterns explain how to assemble objects and classes into larger structures, while keeping the structures flexible and efficient.

  • Behavioral patterns take care of effective communication and the assignment of responsibilities between objects.

注释:

三者为OOP领域需要面对的三种需求:

OOP中基础元素对象的创建;

OOP中复合对象的创建;

OOP中不同对象之间的关系定义;

 

Creational Design Patterns

 

 

Structural Design Patterns

 

 

Behavioral Design Patterns

 

 Code Sample Python

https://refactoring.guru/design-patterns/python

 

 

标签:object,how,guru,patterns,design,Design,设计模式
来源: https://www.cnblogs.com/lightsong/p/15915079.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有