Design Patterns in Smalltalk MVC 在Smalltalk的MVC设计模式
Design Patterns in Smalltalk MVC在Smalltalk的MVC设计模式
The Model/View/Controller (MVC) triad ofclasses [KP88] is used to build user interfaces in Smalltalk-80. Looking at thedesign patterns inside MVC should help
you see what we mean by the term"pattern."
模型/视图/控制器(MVC)类[kp88 ] 是用来在Smalltalk-80构建用户界面。关注在MVC 中的设计模式,会帮助我们理解模式这一术语。
MVC consists of three kinds of objects. TheModel is the application object, the View is its screen presentation, and theController defines the way the user interface reacts to user input. Before MVC,user interface designs tended to lump these objects together. MVC decouples themto increase flexibility and reuse.
MVC有三种对象。模型是应用程序对象,视图是屏幕介绍,控制器其定义了用户在输入之前界面做出反应的方法。用户界面通常把它们结合在一起。MVC减弱它们的结合来增加灵活性和重用性。
MVC decouples views and models byestablishing asubscribe/notify protocol between them. A view must ensure that its appearance reflects the state of the model.Whenever the model's data changes, themodel notifies views that depend on it. In response, each view gets an opportunityto update itself. This approach lets you attach multiple views to a model to providedifferent presentations. You can also create new views for a model withoutrewriting it.
通过视图和模型之间的协议,MVC减弱了它们。视图必须可靠,因为它表达了模型的状态。无论什么时候模型数据改变,模型所确定的视图也依赖它。为此,视图得到了更新它的机会。这种方法使多功能的视图和模型提供的介绍联系在一起了,你也可以创建一个新的视图而不需要重写它。
The following diagram shows a model andthree views. (We've left out the controllers for simplicity.) The model contains somedata values, and the views defining a spreadsheet, histogram, and pie chartdisplay these data in various ways. The model communicates with its views when itsvalues change, and the views communicate
with the model to access these values.
接下来的图表展示了模型和三个视图的关系。(没有添加控制器只是为了简单的说明情况)模型包含了一些数值,视图定义了直方图,电子表格,饼状图等不同的方法来显示这些数据。模型和视图通信在数据改变的时候。视图和模型通信在模型获得这些数据的时候。
Taken at face value, this example reflects a design that decouples views from models. But the design is applicable to amore general problem: decoupling objects so that changes to one can affect anynumber of others without requiring the changed object to know details of the others. Thismore general design is described by the Observer (page 326) design pattern.
从表面看,这个例子表明了设计中减弱了来自模型的视图。但是这个设计的使用有些普遍存在的问题:减弱对象会导致这种改变影响对象中其他的没有要求改变数据,以至于需要知道其他数据的详细。通过观察设计模式,更普遍的设计是描述。
Another feature of MVC is that views can be nested. For example, a control panel of buttons might be implemented as a complex view containing nested button views.The user interface for an object inspector can consist of nested views thatmay be reused in a debugger. MVC supportsnested views with the Composite View class,a subclass of View. CompositeView objects act just likeView objects; a composite view can be used wherever a view can beused, but it also contains and manages nested views.
MVX的另一个特点是视图可以被嵌套。例如,复杂的视图包含嵌套的视图,这样的控制面板按钮可能会被实现。对象检测员的用户界面可以由嵌套的视图组成,在调试的过程中可以被重用。通过综合的视图类和视图的子类,MVC支持嵌套的视图。综合视图对象的行为就像视图对象。视图的子类可以被用在任何需要用视图的地方,它也含有和管理嵌套视图。
Again, we could think of this as a designthat lets us treat a composite view just like we treat one of its components.But thedesign is applicable to a more general problem, which occurs whenever we wantto group objects and treat the group like an individual object. This moregeneral design is described by the Composite (183) design pattern. It lets youcreate a class hierarchy in which some subclasses define primitive objects(e.g., Button) and other classes define composite objects (CompositeView) thatassemble the primitives into more complex objects
在我们可以考虑设计时,对待设计就像对待综合视图中的每一个视图构成要素那样.但是这个设计在应用时可能会有一些普遍比存在的问题。这些会发生在我们想要组对象或对待这个组对像一个独立的对象一样。更普遍的设计是通过综合设计模式来描述。在子类定义原始对象或其他类创建综合对象组成更复杂的对象的时候,它会让你创建类的层次。
MVC also lets you change the way a viewresponds to user input without changing its visual presentation. You might want tochange the way it responds to the keyboard, for example, or have it use a pop-up menuinstead of command keys. MVC encapsulates the response mechanism in a Controllerobject. There is a class hierarchy of controllers, making it easy to create a newcontroller as a variation on an existing one.
MVC也提供视图回应在用户输入没有改变的时候的视觉显示改变的方法。你可能想改变回应键盘输入额方法。例如,用弹出的菜单来代替命令键。MVC的控制器对象包含了所有的回应结构。有类的层次控制,使它更容易在现有的变化中创建新的控制结构。
A view uses an instance ofa Controller subclass toimplementa particular response Strategy to implement a different strategy, simply replace the instancewith a different kind of controller. It's evenpossible to change a view's controller at run-time to let the view change the wayit responds to user input. For example, a view can be disabled so that it doesn'taccept input simply by giving it a controller that ignores input events.
一个视图使用控制器实现特别的响应策略的实例,来实现用不同的方案,用不同的控制器做出简单回应的实例。改变视图控制器,这样做是可能的,在程序运行时,改变视图回应用户进行输入的方法。例如,视图可以不起效,通过一个忽略输入信息的控制器,让它不接受用户的输入。
The View-Controller relationship is anexample of the Strategy (349) design pattern. A Strategy is an object that represents analgorithm. It's useful when you want to replace the algorithm either staticallyor dynamically, when you have a lot of variants of the algorithm, or when thealgorithm has complex data structures that you want to encapsulate.
在349页的设计模式中,有视图控制关系的范例。一个方案是对象是一个算法。你想动态或静的代替这个算法时,当你有各种各样的算法时,或者是算法有复杂的数据结构,你想去囊括它时,它都是有晓得。。
MVC uses other design patterns, such asFactory Method (121) to specify the default controller class for a view and Decorator(196) to add scrolling to a view. But the main relationships in MVC are given bythe Observer, Composite, and Strategy design patterns.
MVC也用其他的设计模式,例如工厂模式为视图指定默认控制结构类和装饰添加滚动视图。但是最主要的关系通过观察,比较,分析,得出设计模式。
Design Patterns in Smalltalk MVC 在Smalltalk的MVC设计模式的更多相关文章
- Cloud Design Patterns: Prescriptive Architecture Guidance for Cloud Applications 云设计模式:云应用的规范架构指导
1.Cache-aside Pattern 缓存模式 Load data on demand into a cache from a data store. This pattern can impr ...
- 设计模式(Design Patterns)
设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- 设计模式(Design Patterns)Java版
设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- java Design Patterns
设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- Java基础学习总结(37)——Java23中设计模式(Design Patterns)详解
设计模式(Design Patterns) --可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...
- 为什么MVC不是一种设计模式
http://damoqiongqiu.iteye.com/blog/1949256 ---比较Backbone和Ext4.x在MVC实现上的差异 大漠穷秋 前言 圣人云:不想做妈咪的小姐不是好码农. ...
- 为什么MVC不是一种设计模式(转)
MVC(Model-View-Controller)是处理界面应用程序时常用的解决方案,构成了表示层. MVC通过分离模型.视图.控制器在应用程序中的角色,实现界面和业务逻辑的解耦.Model(是OO ...
- 为什么MVC不是一种设计模式? ---比较Backbone和Ext4.x在MVC实现上的差异
为什么MVC不是一种设计模式? ---比较Backbone和Ext4.x在MVC实现上的差异 大漠穷秋 前言 圣人云:不想做妈咪的小姐不是好码农. 每一个码农的心中都有一个终极理想,那就是有一天不用再 ...
- 为什么MVC不是一种设计模式?
引用一段话: GoF (Gang of Four,四人组, <Design Patterns: Elements of Reusable Object-Oriented Software> ...
随机推荐
- C语言宏的高级应用
原文:C语言宏的高级应用 关于#和##在C语言的宏中,#的功能是将其后面的宏参数进行字符串化操作(Stringfication),简单说就是在对它所引用的宏变量通过替换后在其左右各加上一个双引号.比如 ...
- php连接sql server 2008数据库
原文:php连接sql server 2008数据库 关于php连接sql server 2008的问题,2000的版本可以直接通过php中的配置文件修改,2005以上的版本就不行了,需要使用微软公司 ...
- AutoCAD 2012安装错误,与.net framework (1603错误)以及ms2005vc++的问题。
首先,这是AutoCAD2012的问题.因为,如果一台计算机已经安装了这些软件,AutoCAD是无法识别出来,因此AutoCAD就只能报错.正确的做法是:如果检测到这些软件已经被安装,则需要忽略这些问 ...
- [Nhibernate]二级缓存
[Nhibernate]二级缓存 目录 写在前面 文档与系列文章 二级缓存 Nhibernate二级缓存提供程序 一个例子 总结 写在前面 上篇文章介绍了nhibernate中一级缓存的相关内容,一级 ...
- Linux下的C程序如何调用系统命令,并获取系统的输出信息到C程序中
直接贴代码: #include <stdio.h> #include <string.h> #include <errno.h> int main(int argc ...
- openwrt路由器更换了Flash之后需要修改的源码
假如我使用的是WR703N,改为8M内存: 1 修改openwrt/target/linux/ar71xx/image/Makefile文件 $(eval $(call SingleProfile,T ...
- Android 使用Gson解析json案例具体解释
一.眼下解析json有三种工具:org.json(Java经常使用的解析),fastjson(阿里巴巴project师开发的),Gson(Google官网出的),解析速度最快的是Gson,下载地址:h ...
- Wijmo 5 + Ionic Framework之:费用跟踪 App
Wijmo 5 + Ionic Framework之:费用跟踪 App 费用跟踪应用采用了Wijmo5和Ionic Framework创建,目的是构建一个hybird app. 我们基于<Mob ...
- hdu 1059 Dividing 多重背包
点击打开链接链接 Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 【转】 Android用于提示等待的ProgressDialog
原文地址:http://blog.csdn.net/wleing/article/details/6086321 为了安抚用户等待的焦急心情,我们用ProgressDialog.它的用法书上有例子,就 ...