Ten most commonly used design patterns
来源:互联网 发布:christmas lights 知乎 编辑:程序博客网 时间:2024/05/14 09:41
1. The Facade Pattern
Provide a unified interface to a set of interfaces in a subsystem. It defines a higher-level interface that makes the subsystem easier to use.
Only works when:
1.use a subset of the system's capabilities
2.interact with it in a particular way
Variations:
1.reduce the number of objects a client must work with
2.provide new functions
3.hide the system
2. The Adapter Pattern
Convert the interface of a class into another interface that the clients expect.It lets classes work together that could not otherwise because of incompatible interfaces.
When to use:
Create a new interface for an object that does the right stuff but has the wrong interface.
How to use:
1.define the interface and then implement in derived classes
2.the derived class contains the existing class which to be used but has wrong interface, then passes request made to it on through to that class
It frees you from worrying about existing interfaces.
Two types:
1.Object Adapter pattern - it relies on one object containing another.
2.Class Adapter pattern - implement useing multiple inheritance
Difference: A Facade simplifies an interface while an Adapter converts the interface into a preexisting interface.
3. The Bridge Pattern
De-couple an abstraction from its implementation so that the two can vary independently.
-- This pattern is a bit hard to understand at first! But it is a challenging pattern to learn cause it is so powerful.
*** implementation here means the objects that the abstract class and its derivations use to implement themselves with, not the derivations of the abstract class,which are called concrete classes.
You cant always see the variations at the beginning of the problem.
Bottom line: During requirements definition, explore for variations early and often!
It is more useful to focus on the context of the pattern - the problem it is trying to solve.This lets you know when and why to use it.
You can identify when to apply a pattern before knowing exactly how to implement it.
The bridge pattern is useful when:
You have an abstraction that has different implementations. It allows the abstraction and the implementation to vary independently of each other.
Commonality/Variability analysis:
Commonality - the search for common elements that helps us understand how family members are the same.Thus, the process of finding out how things are common defines the family in which these elements belong(where things vary).
It seeks structure that is unlikely to change over time.
Variability - reveals how family members vary.It only makes sense within a given commonality.
It captures structure that is likely to change.
It is suggested that using commonality/variability analysis as a primary tool in creating objects is a better approach than looking at just nouns and verbs.
- Ten most commonly used design patterns
- 8 Commonly Used Scalable System Design Patterns
- Most commonly used AS400 commands
- Some of the most commonly used libraries for application development
- Git The most commonly used git commands are
- Design Patterns used in actual Example
- Commonly Used Afx Functions
- android commonly used
- some commonly used websites
- Program Commonly Used Skill
- MapReduce Design Patterns(3. Top Ten))(六)
- 500 Casual Expressions Commonly Used
- Regular expressions are commonly used
- The Design Patterns Used in PetStore 1. Facade
- The Design Patterns Used in PetStore 2. Command
- Design Patterns used in Eclipse Plugins Development(DMIDE)
- Some design patterns were used in the projects
- Port Assignments for Commonly Used Services
- 进程简介
- 程序人生 : 一个程序员的奋斗历程
- Rational rose生成代码及其反向工程功能手册(节选)
- [推荐]请不要做浮躁的人
- 教你理解复杂的C/C++声明 zz1
- Ten most commonly used design patterns
- 理解c中复杂的声明语法
- program(连接)
- 高效使用FORTRAN数组
- 游戏外挂制作指南 (一)
- C语言的字符串操作
- 降低程序的优先级别
- 如何让intel fortran支持2G以上大文件
- 网络socket编程指南zz