designs\project\designPatterns

阅读: 评论:0

designsprojectdesignPatterns

designsprojectdesignPatterns

本文除了状态机的数学定义是从课本上摘录的以外,其他的数学定义均为博主原创。所以,额,如有谬误,敬请留言批评指正。^%^。

感谢Head First Design Patterns 的作者们 Eric Freeman, Elisabeth Freeman, Kathy Sierra, and Bert Bates;在阅读完成本书后,结合discrete mathematics为本博文提供了创作灵感。

I prefer to describe design patterns without any graphical umls.

原则1:Identify the aspects of your application that vary and separate them from what stays the same.

原则2:Program to an interface, not an implementation.

原则3:Favor composition over inheritance.

 

The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

策略 S=(f, Ο) 其中f代表Formulating后的算法封装;Ο 代表分治的a family of algorithms也就是所有被封装的算法的实现implementing;

Formulating包括分析环境或情况,作出诊断,制定指导方针。它包括战略规划和战略思维等活动

 

 

原则4:Strive for loosely coupled designs between objects that interact

 

The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.

发布-订阅 O = (S, E, R), E⊆S, R={(pub, sub) | sub OBSERVERS pub}。 S表示所有内部状态; E表示state变化事件event;R代表Observers观察Subject的关系;

 

 

原则5:Classes should be open for extension, but closed for modifi cation.

 

The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorators provide a fl exible alternative to subclassing for extending functionality.

前缀/后缀:If x,y∈∑* and w=xy, then the string x is called a prefix of w, and y≠λ, then x is said to be a proper prefix. Similarly, the string y is called a suffix of w; it is a proper suffix when x≠λ.

装饰:R={(w, x, y) | w=xy, x,y∈∑*}

 

 

原则6:Depend upon abstractions. Do not depend upon concrete classes.

 

The Factory Method Pattern defi nes an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.

The Abstract Factory Pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.

分组:A = Ui∈IAi????

 

The Singleton Pattern ensures a class has only one instance, and provides a global point of access to it.

单例:I=(f, R) R={(x,c) | x属于类型c, |{x}| = 1}。 f表示{} -> x获得类型c的实例x的方法;R代表x是某个类的实例,且这个实例是可数的,通常是1个;

 

 

The Command Pattern encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.

命令:Command= ute(x)=Receiver.action(x)

 

 

原则7:Principle of Least Knowledge talk only to your immediate friends.

 

The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

The Facade Pattern provides a unifi ed interface to a set of interfaces in a subsytem. Facade defi nes a higherlevel interface that makes the subsystem easier to use.

适配/门面:Adapter=(interface_f, R) R={A,B| A与B的适配 or A与B的门面} interface_f  R->R表示关系R的访问接口;R表示A与B的适配关系,或者门面关系;

 

 

原则8:Don’t call us, we’ll call you.

 

The Template Method Pattern defi nes the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefi ne certain steps of an algorithm without changing the algorithm’s structure.

模板方法:F={(o1, o2,…) | oi∈O}  O={(A,B,C,…) | A->B,…};F封装算法流程;O表示封装算法操作;

 

 

原则9:A class should have only one reason to change.

 

The Iterator Pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation.

The Composite Pattern allows you to compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

迭代/组合:I = {R1, R2} R1= {a relation on Data A} R2= {another relation on Data A like iterator or composite} R1表示数据 A上的原有业务逻辑;R2表示数据A的迭代/组合方法。

(举个栗子:public string Property property { get; set;},大家看这个Property,他既然是Public的。还写个get,set方法,是不是很多余呢?这个问题困惑了我好多年。但是,自从学习了原则9:A class should have only one reason to change.之后。I={R1,R2},其中R1表示Property是某个类Class的属性是Has a的关系,R2表示Property和Property的实例property之间又可以有is a关系,栗如:以下的设计 public 大傻 小傻 {get小傻; set小傻}我家有个大傻,大傻生了一个小傻!0!)

 

 

The State Pattern allows an object to alter its behavior when its internal state changes. The object will appear to change its class.

状态机M=(S, φ, Ο, v, w) 其中S 表示M的内部状态集; φ 表示M的输入字符集 ; Ο 表示 M的输出字符集; v 表示S X φ -> S是下一个状态函数,状态变迁函数,接受上一个状态S和本次输入φ 作为参数;w 表示S X φ –> Ο,是输出函数,接受上一个状态S和本次输入φ 作为参数。

 

 

The Proxy Pattern provides a surrogate or placeholder for another object to control access to it.

代理:R={{A, B}, {B, C}} B表示A与C中间的代理。

本文发布于:2024-01-27 17:04:18,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063462571543.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23