📜  设计模式-概述

📅  最后修改于: 2020-12-21 01:57:23             🧑  作者: Mango


设计模式代表了经验丰富的面向对象软件开发人员所使用的最佳实践。设计模式是软件开发人员在软件开发过程中面临的一般问题的解决方案。这些解决方案是由众多软件开发人员在相当长的一段时间内通过反复试验获得的。

什么是四人帮(GOF)?

1994年,四位作者Erich Gamma,Richard Helm,Ralph Johnson和John Vlissides出版了一本书,名为《设计模式-可重用的面向对象软件的元素》,该书提出了软件开发中的设计模式的概念。

这些作者被统称为四人帮(GOF) 。这些作者认为,设计模式主要基于以下面向对象设计的原理。

  • 编程到接口而不是实现

  • 优先考虑对象组成而不是继承

设计模式的使用

设计模式在软件开发中有两种主要用法。

开发人员通用平台

设计模式提供了标准术语,并且特定于特定场景。例如,单例设计模式表示使用单个对象,因此所有熟悉单一设计模式的开发人员都将使用单个对象,并且他们可以彼此告知程序正在遵循单例模式。

最佳实践

设计模式已经发展了很长时间,它们为软件开发过程中遇到的某些问题提供了最佳解决方案。学习这些模式可帮助没有经验的开发人员以简便快捷的方式学习软件设计。

设计模式的类型

根据设计模式参考书《设计模式-可重用的面向对象软件的元素》 ,共有23种设计模式,可分为三类:创建模式,结构模式和行为模式。我们还将讨论设计模式的另一类:J2EE设计模式。

S.N. Pattern & Description
1 Creational Patterns
These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This gives program more flexibility in deciding which objects need to be created for a given use case.
2 Structural Patterns
These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalities.
3 Behavioral Patterns
These design patterns are specifically concerned with communication between objects.
4 J2EE Patterns
These design patterns are specifically concerned with the presentation tier. These patterns are identified by Sun Java Center.