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> ...
随机推荐
- HDU 4228 Flooring Tiles 反素数
推出了结论,万万没想到最后用搜索.. 还想dp来着.. #include <cstdio> #include <cstring> #include <iostream&g ...
- java设计模式之四建造者模式(Builder)
工厂类模式提供的是创建单个类的模式,而建造者模式则是将各种产品集中起来进行管理,用来创建复合对象,所谓复合对象就是指某个类具有不同的属性,其实建造者模式就是前面抽象工厂模式和最后的Test结合起来得到 ...
- ASP.NET MVC创建的网站
ASP.NET MVC创建的网站 最近在写一个网站,昨天刚写完,由于要和朋友一起测试,但是他电脑上没有环境,所以希望我在自己电脑上部署一下,让他直接通过浏览器来访问来测试,所以从昨晚到今天上午,通 ...
- Mvc 下载文件
你如何将文件传送给用户取决于你最开始如何存储它,如果你将文件存入数据库,你会用流的方式将文件返还给用户,如果你将文件存在硬盘中,你只需要提供一个超链接即可,或者也可以以流的方式.每当你需要以流的方式将 ...
- POJ3187 Backward Digit Sums
给出杨辉三角的顶点值,求底边各个数的值.直接DFS就好了 #include<iostream> #include<cstdio> #include<cstring> ...
- C语言中的内存管理
开始陆续的发一下唐老师视频的笔记吧,顺便带一些正冲哥书的的内容.不能一下都发出来,因为内容发多了自己也受不了,而且发的都是学习视频时候的一些笔记,可能会有一些问题不是很清晰. 先说一下C语言中的内存管 ...
- wpa_cli P2P 连接相关的调试命令
在最近的一次客户端上的调试p2p的wifi display, 他们中的一半Android该调整了,整个前所以没有太多的研究p2p过程连接, 客户现在使用的非Android平台架构. 需要协助客户这么多 ...
- JDK6、Oracle11g、Weblogic10 For Linux64Bit安装部署说明
JDK6.Oracle11g.Weblogic10 For Linux64Bit安装部署说明 项目编号 编写人 成 编写日期 2013/07/29 审核 修订说明 目录 JDK6.ORACLE11G. ...
- openGL绘制正方形
/** * 缓冲区工具类 */public class BufferUtil { /** * 将浮点数组转换成字节缓冲区 */ public static ByteBuffer arr2ByteB ...
- Tween动画
知识点 Alpha:渐变透明度动画效果 Scale:渐变尺寸伸缩动画效果 Translate:移动效果 Rotate:旋转效果 1. AlphaAnimation(float fromAlpha,fl ...