张志敏的技术专栏

结构 说明 Define a one-to-many dependency between objects where a state change in one object results with all its dependents being notified and updated automatically. 在对象间定义一个一对多的联系性,由此当一个对象改变了状态,所有其他相关的对象会被通知并且自动刷新。 适用条件 当抽象个体有两个相互依赖的层面时。 封装这些层面在单独物件内将可允许程序设计师单独地去变更与重复使用这些物件, 而不会产生两者之间的交互问... 阅读全文

设计模式 2013-11-11

结构 说明 Without violating encapsulation, capture and externalize an object’s internal state allowing the object to be restored to this state later. 在不破坏封装的条件下,将一个对象的状态捉住,并外部化,存储起来,从而可以在将来合适的时候把这个对象还原到存储起来的状态。 适用条件 需要保存对象在某一时刻的状态, 并在以后需要将对象恢复到这个状态; 同时又不希望暴露对象的实现细节, 破坏对象的封装性, 这是需要使用备忘录模式。 实现 ... 阅读全文

设计模式 2013-11-08

简介 本文介绍在应用程序中使用 ASP.net MVC 5 Attribute Routing 最新特性; 本文分两部分, 第一部分介绍 Attribute Routing 的基本用法, 第二部分介绍一些高级用法。 什么是 Routing ? Routing 是 ASP.net MVC 将地址映射为 Action 方法的技术。 什么是 Attribute Routing ? ASP.net MVC 5 支持一种新类型的路由, 称之为 Attribute Routing 。 顾名思义, Attribute Routing 使用来标记定义路由, Attribute Ro... 阅读全文

升级到 VS2013 之后, 编译时会发现 VS2013 下 NuGet 不能正确识别预先配置好的存放目录, 总是把文件放在解决方案的 packages 目录下, 这个可以说是 NuGet 的 bug , 也可以说是 VS2013 的 bug , 原因是: 安装 VS2013 时, 会自动生成文件 %ProgramData%\NuGet\Config\VisualStudio\12.0\Microsoft.VisualStudio.config , 这个文件为 VS2013 配置了一个特殊的源 Microsoft and .NET , 内容如下: <?xml version="... 阅读全文

NuGet 2013-11-03

结构 说明 Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. 包装了一系列对象相互作用的方式,使得这些对象不必相互明显作用,从而使它们可以松散偶合。当某些对象之间的作用发生改变时,不会立即影响其他的一些对象之... 阅读全文

设计模式 2013-11-03

结构 说明 Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation. 提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示。 适用条件 迭代器模式是非常常见的设计模式之一, 适用条件很广, 需要访问聚合对象(数组、集合、列表等)的元素时, 即可使用迭代器模式。 实现 public interface IIterator { object CurrentItem... 阅读全文

设计模式 2013-11-02

结构 说明 Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. 给定一个语言, 定义它的文法的一种表示,并定义一个解释器, 该解释器使用该表示来解释语言中的句子。 适用条件 当有一个语言需要解释执行, 并且可以将语言中的句子表示为一个抽象的表达式树时, 可以使用解释器模式。 实现 以逆波兰表示法为例, 其语法为: ex... 阅读全文

设计模式 2013-10-24

结构 说明 This pattern encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. 这个模式将请求封装成一个对象, 从而可以不用的请求对客户进行参数化, 对请求排队或者记录请求日志, 以及支持可以取消的操作。 适用条件 行为需要扩充, 将命令作为对象处理, 新的行为可以通过扩充子类完成; 命令需... 阅读全文

设计模式 2013-10-23

结构 说明 This pattern avoids coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. It chains the receiving objects and passes the request along the chain until an object handles it. 使多个对象都有机会处理请求, 从而避免了请求的发送者与接收者之间的耦合。 将接收对象组成链, 在链上传递请求,... 阅读全文

设计模式 2013-10-22

设计模式四人帮 设计模式四人组GoF(“四人帮”,又称Gang of Four,即Erich Gamma, Richard Helm, Ralph Johnson & John Vlissides四人)的《设计模式》,原名《Design Patterns: Elements of Reusable Object-Oriented Software》(1995年出版,出版社:Addison Wesly Longman.Inc),第一次将设计模式提升到理论高度,并将之规范化。该书提出了23种基本设计模式。时至今日,在可复用面向对象软件的发展过程中,新的设计模式仍然不断出现。 ... 阅读全文

设计模式 2013-10-21

新建 Xcode workspace 打开 Xcode , 选择 File -> New -> Workspace , 将 Workspace 命名为 Test.xcworkspace , 并选择合适的目录。 新建 Static Library 项目 选择 File -> New -> Project , 项目模板选择 Cocoa Touch Static Library , 项目名称命名为 MyLib.xcodeproj , 注意选中 Use Automatic Reference Counting 。 Xcode 会在项目中自动生成 MyLib... 阅读全文

iOS 2013-10-20

initWithFormat 还是 stringWithFormat ? initWithFormat 是实例方法,用法如下: NSString* str = [[NSString alloc] initWithFormat:@"%@", @"Hello, world!"]; self.label.text = str; [str release]; 如果是运行在在 iOS 5.0 之前或者没有使用 ARC 的情况下, 需要手工调用 release 方法进行回收。 stringWithFormat 是类方法, 用法如下: NSString* str = [NSString s... 阅读全文

iOS 2013-10-18