2019独角兽企业重金招聘Python工程师标准>>>

How MVC works

MVC is a design pattern that enforces the separation between the input, processing, and output of an application. To this end, an application is divided into three core components: the modelview, and controller. Each of these components handles a discreet set of tasks.

The superiority

Using three components of MVC, you can open up new levels of robustnesscode reuse, and organization.

The Singleton Pattern

The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance. It usually uses lazy loading to create the single instance when it’s needed the first time.

The Facade Design Pattern

The Facade design pattern provides a single interface to a complex subsystem. Instead of exposing the user to a set of classes and their APIs, you only expose one simple unified API.

The Decorator Design Pattern

The Decorator pattern dynamically adds behaviors and responsibilities to an object without modifying its code. It’s an alternative to subclassing where you modify a class’ behavior by wrapping it with another object. In Objective-C there are two very common implementations of this pattern: Category and Delegation.

Category

Category is an extremely powerful mechanism that allows you to add methods to existing classes without subclassing. The new methods are added at compile time and can be executed like normal methods of the extended class. It’s slightly different from the classic definition of a decorator, because a Category doesn’t hold an instance of the class it extends.

Delegation

The other Decorator design pattern, Delegation, is a mechanism in which one object acts on behalf of, or in coordination with, another object. For example, when you use a UITableView, one of the methods you must implement is tableView:numberOfRowsInSection:.

The Adapter Pattern

An Adapter allows classes with incompatible interfaces to work together. It wraps itself around an object and exposes a standard interface to interact with that object.

The Observer Pattern

In the Observer pattern, one object notifies other objects of any state changes. The objects involved don’t need to know about one another – thus encouraging a decoupled design. This pattern’s most often used to notify interested objects when a property has changed. The usual implementation requires that an observer registers interest in the state of another object. When the state changes, all the observing objects are notified of the change. Apple’s Push Notification service is a global example of this. If you want to stick to the MVC concept (hint: you do), you need to allow Model objects to communicate with View objects, but without direct references between them. And that’s where the Observer pattern comes in.

Cocoa implements the observer pattern in two familiar ways: Notifications and Key-Value Observing (KVO).

Notifications

Notifications are based on a subscribe-and-publish model that allows an object (the publisher) to send messages to other objects (subscribers/listeners). The publisher never needs to know anything about the subscribers.

Key-Value Observing

In KVO, an object can ask to be notified of any changes to a specific property; either its own or that of another object.

The Memento Pattern

The memento pattern captures and externalizes an object’s internal state. In other words, it saves your stuff somewhere. Later on, this externalized state can be restored without violating encapsulation; that is, private data remains private.

Archiving

One of Apple’s specialized implementations of the Memento pattern is Archiving. This converts an object into a stream that can be saved and later restored without exposing private properties to external classes.

The Command Pattern

The Command design pattern encapsulates a request or action as an object. The encapsulated request is much more flexible than a raw request and can be passed between objects, stored for later, modified dynamically, or placed into a queue. Apple has implemented this pattern using the Target-Action mechanism and Invocation.

Reference of this tutorial  iOS Design Pattern. Thanks a lot to Eli Ganem.

Sep 28, 2015

转载于:https://my.oschina.net/herbert77/blog/500622

iOS Design Patterns Excerpt相关推荐

  1. 《Design Patterns Explained》读书笔记

    Design Patterns Explained: A New Perspective onObject-Oriented Design 作者:Alan Shalloway, James R. Tr ...

  2. 艾伟_转载:C# Design Patterns (3) - Decorator

    Decorator Pattern (装饰模式) 装饰模式可「动态」地给一个对象添加一些额外的职责,提供有别于「继承」的另一种选择.就扩展功能而言,Decorator Pattern 透过 Aggre ...

  3. 艾伟_转载:C# Design Patterns (4) - Proxy

    本帖介绍 Proxy Pattern (代理模式). Proxy Pattern (代理模式) The Proxy Pattern provides a surrogate or placeholde ...

  4. 检索com类工厂 80070005_Hands-On Design Patterns With C++(十二)友元工厂

    目录: trick:Hands-On Design Patterns With C++(零)前言​zhuanlan.zhihu.com 友元工厂 c++中,友元用于给予其他类访问权限.本章具体讨论以下 ...

  5. 架构与设计 之一 C 嵌入式设计模式(Design Patterns for Embedded Systems in C)的学习记录

    唉   时至今日,已经不知道在嵌入式的道路上到底挣扎了多少个岁月,总感觉要"病入膏肓"了.此间总是不时出现一些疑惑:人家搞 Java.搞 C# 的动不动就是什么架构 / 框架的,搞 ...

  6. Design Patterns in Java

    <Design Patterns in Java> 作者:Steven John Metsker,William C. Wake 出版日期:2006-04-28 语言:English 版本 ...

  7. 设计模式(Design Patterns)详解

    设计模式(Design Patterns) --可复用面向对象软件的基础一般会用到的: Factory( 工厂模式) Singleton(单例模式) 这两个比较多 Proxy(代理模式) Adapte ...

  8. Rethinking Design Patterns - from Jeff Atwood

    本文出处[1] ... It's certainly worthwhile for every programmer to read Design Patterns at least once, if ...

  9. 艾伟:C# Design Patterns (1) - Factory Method

    Simple Factory Pattern (简单工厂模式) 特性: 把类的实例化工作,集中到一个「工厂类」去处理,亦即将 new instance 的工作,都交给一个「工厂」去处理,而不要分散写在 ...

  10. Java23中设计模式(Design Patterns)详解

    2019独角兽企业重金招聘Python工程师标准>>> 设计模式(Design Patterns) --可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复 ...

最新文章

  1. CNN为何把地震和计划生育扯一起
  2. C#中显/隐式实现接口及其访问方法
  3. 400分理科学计算机,理科400分能上哪些大学 高考400分算什么水平
  4. max复制关键帧到不同的文件_彭占元|如何排除PostgreSQL WAL 文件数量长期持续增加?...
  5. golang beego安装及入门示例
  6. MySQL分页查询慢的方案解决
  7. go获取项目内所有proto_gRPC学习之三:初试GO版gRPC开发
  8. 云小课|RDS实例连接又失败?看我祭出杀手锏!
  9. PaddlePaddle飞桨OCR文本检测——识别模型训练(三)
  10. [编程题]手机屏幕解锁模式
  11. Execl导出大量数据出现内存溢出的bug,解决方法
  12. linux救黑砖手机,手机黑砖9006/9008救砖教程 通用救砖模式详细流程
  13. nv驱动版本linux,NV显卡Linux版驱动双响炮:一正式一测试
  14. 服务器共享文件夹Windows无法访问,windows server 2008 R2 无法访问本机共享文件夹
  15. java 两个url对比_一个URL模式中的两个slu ..
  16. 数据中台各种架构图大全
  17. 萤石网络摄像机 服务器压力,萤石C3W监控摄像头真的很不堪吗,不想被骗看下这里...
  18. Greenfoot游戏项目_水果篮子
  19. iOS 客户端基于 WebP 图片格式的流量优化(下)
  20. 想要做好软件测评,在这之前这20个小技巧得知道

热门文章

  1. Root Mi note lte with SuperSU without flashing TWRP Recovery permanently (by quqi99)
  2. <4>STM32F103基础知识
  3. 键盘哪个键是锁定计算机,键盘锁是哪个键 锁键盘的是哪个键 - 云骑士一键重装系统...
  4. 2004年1月六级听力原文的启示:每顿饭后刷牙牙齿好
  5. 交换机与路由器技术:静态路由配置和路由器上配置DHCP、虚拟局域网VLAN
  6. Kali对网站进行DDOS攻击
  7. Vue中Class和Style几种v-bind绑定的用法-详解案例
  8. 百度应用开放平台简介
  9. (四)下载利器aria2
  10. c# autoscroll_禁用Firefox中令人讨厌的AutoScroll功能