Notes on Design Patterns

一些笔记。

  • strategy : facilitates the switch of the different but related algorithms/behaviors
  • observer
  • proxy : controls the access to the real subject ; shares the common interface with the real subject and sometimes provides a subset of the operations in the interface (in the case of the protection proxy)

e.g. there are three kinds of proxies : (1) the remote proxy (surrogate the subject in the different address space); (2) the virtual proxy (SqlSessionTemplate in the mybatis.spring which is a proxy of the SqlSession); (3) the protection proxy (usually used in the os to control access to critical resouces)

  • template method : constructs the skeleton of the algorithm and leaves the variant part to be implemented by the subclasses
  • adapter : provides a uniform interface to the client which hides the different classes, usually inaccessible to clients

TO-DO: Open-Close Principle:

Conclusion

Like every principle OCP is only a principle. Making a flexible design involves additional time and effort spent for it and it introduce new level of abstraction increasing the complexity of the code. So this principle should be applied in those area which are most likely to be changed.

There are many design patterns that help us to extend code without changing it. For instance the Decorator pattern help us to follow Open Close principle. Also the Factory Method or the Observer pattern might be used to design an application easy to change with minimum changes in the existing code.

原文地址:https://www.cnblogs.com/huangzejun/p/8143805.html

时间: 2024-08-06 11:36:24

Notes on Design Patterns的相关文章

Learning JavaScript Design Patterns The Module Pattern

The Module Pattern Modules Modules are an integral piece of any robust application's architecture and typically help in keeping the units of code for a project both cleanly separated and organized. In JavaScript, there are several options for impleme

Learning JavaScript Design Patterns -- A book by Addy Osmani

Learning JavaScript Design Patterns A book by Addy Osmani Volume 1.6.2 Tweet Copyright © Addy Osmani 2015. Learning JavaScript Design Patterns is released under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 unported license. It

设计模式(Design Patterns)

设计模式(Design Patterns) 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性. 毫无疑问,设计模式于己于他人于系统都是多赢的,设计模式使代码编制真正工程化,设计模式是软件工程的基石,如同大厦的一块块砖石一样.项目中合理的运用设计模式可以完美的解决很多问题,每种模式在现在中都有相应的原理来与之对应,每一个模式描述了一个在我们周围不断重复发生的问题,以及该问

Design Patterns 5 原型模式 Prototype

原型模式 Prototype 原型模式:用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象. 当我们需要多个相同的类实例时,没必要每次都使用new运算符去创建相同的类实例对象,我们可以用原型模式减少内存的消耗和达到类实例的复用. //带有返回自身接口的抽象原型类 public abstract class Prototype5 { public string Id { get; set; } public Prototype5(string id) { this.Id = id;

Cocoa Design Patterns

Book Description This is the Rough Cut version of the printed book. Much of the technology embodied by Apple's Cocoa software development frameworks have been in commercial use since 1988, and in spite of many years of use, the Cocoa frameworks are s

Learning JavaScript Design Patterns The Observer Pattern

The Observer Pattern The Observer is a design pattern where an object (known as a subject) maintains a list of objects depending on it (observers), automatically notifying them of any changes to state. When a subject needs to notify observers about s

[Design Patterns] 4. Creation Pattern

设计模式是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结,使用设计模式的目的是提高代码的可重用性,让代码更容易被他人理解,并保证代码可靠性.它是代码编制真正实现工程化. 四个关键元素:(1) Pattern Name, (2) Problem, (3) Solution, (4) Consequences. 01. Factory Method Pattern /* The product should be created by his own factory. */ Log

MapReduce Design Patterns

1. Design Patterns and MapReduce. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Design PatternsMapReduce HistoryMapReduce and Hadoop RefresherHadoop Example: Word CountPig and Hive 2. Summarization Patter

Design Patterns 4 酒干倘卖无---抽象工厂模式AbstractFactory

抽象工厂模式AbstractFactory 抽象工厂模式:提供一个创建产品的接口来负责创建相关或依赖的对象,而不具体明确指定具体类. 抽象工厂对于系列产品的变化支持 “开放——封闭”原则(指的是要求系统对扩展开放,对修改封闭),扩展起来非常简便,但对于添加新产品这种情况就不支持”开放——封闭 “原则. Design Patterns 4 酒干倘卖无---抽象工厂模式AbstractFactory,布布扣,bubuko.com