`
CherryRemind
  • 浏览: 54836 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Design Patterns and OOP

    博客分类:
  • Base
阅读更多

Design Patterns

 
A design pattern is a recurring solution to a standard problem.

The most well-known design patterns (in total 23) were documented by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides also called The Gang of Four (GOF) in the book Design Patterns -- Elements of Reusable Software (1995).

There a hunderds of design patterns described in the literature. This tutorial only describes the design patterns documented by the GOF.

The GOF has divided the design patterns into three types.

Type name Description
Creational patterns Deal with initializing and configuring classes and objects
  • Abstract Factory
  • Builder Factory
  • Factory Method
  • Prototype Factory
  • Singleton
Structural patterns Deal with decoupling interface and implementation of classes and objects
  • Adapter
  • Bridge
  • Composite
  • Decorator
  • Facade
  • Flyweight
  • Proxy
Behavioral patterns Deal with dynamic interactions among societies of classes and objects
  • Chain of Responsibility
  • Command
  • Interpreter
  • Iterator
  • Mediator
  • Memento
  • Observer
  • State
  • Strategy
  • Template
  • Visitor


Creational patterns.

Name Description
Factory Method Method in a derived class creates associates
Abstract Factory Factory for building related objects
Builder Factory for building complex objects incrementally
Prototype Factory for cloning new instances from a prototype
Singleton Factory for a singular (sole) instance

 

 

 

 

 

knowledge of pattern
#  creational
1. factory method: lazy initialize specific instance

2. abstract factory: supply a interface for the system

3. builder: builder or create a object apart from its descrition

4. prototype: create new object which type base on the type of specific instance

5. singleton: make sure one class only have one instance, supply for every visitor
 allways used with factory pattern together.

# structural
6. adapter: give a interface of class for get another required interface, implement compatibility

7. bridge: extranet abstract class from implement class, make it suit for their single change
public abtract class AbstractRoot
{
    operation();
}

8. composite: make a object as tree structure, make "part-all" clearly. 

组合模式:  ----继承

9. decorator: change extend(8) to delegate

装饰器模式: --- 委托



10. facade: supply a interface for visiting the sub-system



11. flyweight: it seem logic like cache.
     if (flyweight[key] exists)
     {
        return existing flyweight;
     }
     else
     {
        create new flyweight;
        add it to pool of flyweights;
        return the new flyweight;
     }
     
12. proxy:   a, remote proxy       visit
             b, virtual proxy      performance
             c, protection proxy   control
             d, smart reference    get reference number
             
# behavioral
13. interpreter 解释模式

14. Template Method 模版模式 
AIM: 定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。
ENV: 一次性实现一个算法的不变的部分,并将可变的行为留给子类来实现.
TODO: 比较组合模式
 
15. Chain of Responsibility
AIM: 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止.
有多个的对象可以处理一个请求,哪个对象处理该请求运行时刻自动确定。
你想在不明确指定接收者的情况下,向多个对象中的一个提交一个请求。
可处理一个请求的对象集合应被动态指定。

16. Command 命令模式
将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可撤消的操作。


17. Iterator 迭代模式

18. Mediator 仲裁模式

19. Memento  记忆模式

20. Observer 观察者模式

21. State 状态模式
允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它的类。

22. Strategy 策略模式
TODO: 比较State
定义一系列的算法,把它们一个个封装起来, 并且使它们可相互替换。本模式使得算法可独立于使用它的客户而变化。

23. Vistor 访问模式

 

  <head first ooad>

感觉OO原则其实我们平时编码的最基本原则, 设计模式可以就是遵循的OO原则来运用的.
OO principle
#1 the open-closed principle(ocp)
classed shoulde be open for extension, and closed for modification.

#2 the don't repeat yourself principle (DRY)
have each piece of imformation and behavior in your system in a single,sensible place.

#3 the single responsibility principle(SRP)
Single responsibility priciple correctly when each of your objects has only one reason to change

#4 the Liskov substitution priinciple(LSP)
感觉LSP就是用委托....

 

分享到:
评论

相关推荐

    Design Patterns and Object Oriented Programming in Visual Basic 6

    面向对象编程(OOP)是现代软件开发中最常用的一种编程范式,它将程序结构化为相互交互的对象集合。在Visual Basic 6及VB.NET中,OOP的应用十分广泛,下面列举了一些核心概念: - **继承**:继承允许一个类(子类)...

    .NET Design Patterns [Kindle Edition]

    Knowing about design patterns enables developers to improve their code base, promoting code reuse and making their design more robust. This book focuses on the practical aspects of programming in ...

    Design.Patterns.Explained.Simply

    This book is fast and simple way to get the idea behind each of the 29 popular design patterns. The book is not tied to any specific programming language and will be good for you as long as you have a...

    Professional ASP.NET Design Patterns

    Professional ASP.NET Design Patterns will show you how to implement design patterns in real ASP.NET applications by introducing you to the basic OOP skills needed to understand and interpret design ...

    Cambridge.Press.C.plus.plus.Design.Patterns.and.Derivatives.Pricing.Jun.2008

    《Cambridge.Press.C.plus.plus.Design.Patterns.and.Derivatives.Pricing.Jun.2008》这本书聚焦于C++编程语言在金融衍生品定价中的应用,结合设计模式来解决复杂的计算问题。以下是该书可能涉及的重要知识点: 1. ...

    Design Patterns in Java

    本资料《Design Patterns Java Companion》由James W. Cooper撰写于1998年10月2日,版权归属于作者本人。书中全面地介绍了23种常用的设计模式,并通过Java底层类进行深入解析。 #### 设计模式定义及其来源 设计...

    Design-Patterns-in-Modern-C++

    The topic of Design Patterns sounds dry, academically constipated and, in all honesty, done to death in almost every programming language imaginable—including programming languages such as JavaScript...

    Introduction to Design Patterns in C++ with Qt(PrenticeHall,2ed,2011)

    oriented programming texts that teach readers how to program in C++ with standard I/O (e.g., Deitel) and the relatively few books that assume a knowledge of OOP/C++ and emphasize GUI programming using...

    PHP 5 dvanced OOP and Design Patterns

    《PHP 5 高级面向对象编程与设计模式》这本书不仅涵盖了PHP 5中的高级OOP特性,还介绍了如何将这些特性与设计模式结合起来,构建出更加健壮和灵活的应用程序。通过学习本书,开发者可以提升自己的技能水平,写出更加...

    Data Structures and Algorithms with Object-Oriented Design Patterns in C++ 源码

    《Data Structures and Algorithms with Object-Oriented Design Patterns in C++》是关于数据结构与算法的一本经典著作,它深入探讨了如何使用面向对象的设计模式来实现高效的数据结构和算法。这本书通过C++语言来...

    Design_Patterns_Explained.pdf

    《Design_Patterns_Explained》这本书旨在为读者提供一个深入理解设计模式的机会,无论是对于那些已经在使用面向对象语言多年的开发者,还是对面向对象编程还处于学习阶段的新手来说,本书都将是一份宝贵的资源。...

    设计模式解析 design patterns explained

    设计模式作为OOP的一种高级实践形式,不仅能够帮助开发者创建更灵活、可维护的软件系统,还能促进团队间的有效沟通。 - **封装**: 将数据和操作这些数据的方法捆绑在一起,对外部隐藏内部实现细节。 - **继承**: ...

    Design Patterns and Object Oriented Programming in Visual Basic 6 and VB.NET.pdf

    面向对象编程(Object-Oriented Programming,OOP)是一种编程范式,它将数据和操作数据的方法捆绑在一起形成对象。这种编程方式强调封装、继承和多态等特性,能够有效地提高代码的复用性和可维护性。 #### 知识点...

    Design Patterns in Modern C

    《Design Patterns in Modern C++》一书,由Dmitri Nesteruk撰写,重点介绍了在现代C++编程中如何使用设计模式。 首先,要了解设计模式,必须具备面向对象编程(Object-Oriented Programming,简称OOP)的知识。C++...

    Object-Oriented Concepts, Analysis and Design with Patterns

    面向对象编程(Object-Oriented Programming,简称OOP)是一种软件开发方法论,它以“对象”作为基本单位来构建程序,并通过对象之间的交互来实现功能。本课程旨在帮助学员掌握面向对象的基本概念及其在软件开发中的...

Global site tag (gtag.js) - Google Analytics