OOD架构设计模式中MVC与ECB

时间比较紧,先转再翻

http://www.cs.sjsu.edu/~pearce/modules/lectures/ooa/analysis/ecb.htm

日后有相关类似资源将不断更新

The Entity-Control-Boundary Pattern

The analysis object model instantiates theEntity-Control-Boundary Pattern (ECB)

ECB is a simplification of the Model-View-ControllerPattern.

ECB partitions the system into three types of classes:entities, controls, and boundaries.

entity, control, and boundary are official UML classstereotypes. UML has some special icons to represent them:

OOD架构设计模式中MVC与ECB_第1张图片

Here's the same diagram without the special icons:

OOD架构设计模式中MVC与ECB_第2张图片

Entities

Entities are objects representing system data: Customer,Product, Transaction, Cart, etc.

实体类:在系统中充当数据载体的类型,通常来自现实问题中的实体

Boundaries

Boundaries are objects that interface with system actors:UserInterface, DataBaseGateway, ServerProxy, etc.

边界类:系统和外界环境的接口,按照我的理解可以是各种输入数据的来源,文中提到的actor不专指用户,对于一个软件系统来说,所有与之交互,使用其功能的外部实体都可以算作actor


Controls

Controls are objects that mediate between boundaries andentities. They orchestrate the execution of commands coming from the boundaryby interacting with entity and boundary objects. Controls often correspond touse cases and map touse casecontrollers in the design model.

控制类:根据边界类收到的信息,对实体类进行相应的操作,换句话说就是封装了业务逻辑,所以控制类一般和一个或多个用例对应

Internal Dynamics

Associated with every control in the analysis model is astatechart diagram representing the control's internal logic.

表示控制类的内部逻辑

For example:

OOD架构设计模式中MVC与ECB_第3张图片

External Dynamics

Associated with every control is a sequence diagramrepresenting the control's interactions with boundaries, entities, and othercontrols.

表示一个控制类和边界类、实体类以及其他控制类之间的互动逻辑

For example:

OOD架构设计模式中MVC与ECB_第4张图片

Model-View-Controller Pattern

Application data and logic (encapsulated by the model)should be independent of presentation logic (encapsulated by the views andcontrollers).

基本要义:应用的数据和逻辑(对应Model)应当独立于数据的表示逻辑(应该指软件的I/O以及交互逻辑,对应View和Controller)


OOD架构设计模式中MVC与ECB_第5张图片

Views are responsible for user input and output. A dialogbox is a good example of a view. Controllers implement the logic for theallowable transactions that can be performed on the model. The model encapsulatesthe fine grained business logic and data.

视图的职责是向用户提供IO接口,而控制器实现对Model操作的业务逻辑。Model则封装了实体的数据和细粒度的业务逻辑

- 想法:这里的Application data & logic应该是指现实中实体的属性和内在的逻辑(比如香蕉是黄的,可以吃,等等),而不是业务逻辑(用户想要把香蕉炒着吃,该怎么把香蕉炒了送出去,等等)


Here's a sequence diagram showing the interaction:

OOD架构设计模式中MVC与ECB_第6张图片

The Model-View-Controller Architecture

We refine the multi-layer pattern with the Model-View-Controllerpattern:

OOD架构设计模式中MVC与ECB_第7张图片

If our domain layer consists of many classes, we might wantto introduce the Facade pattern to promotedecoupling between the presentation package and the domain package.

如果domain层包含多个类,那么可以考虑引入门面(Facade)模式来实现presentation包和domain包之间的解耦

View Notification

How can the model notify all views when it has been updatedwithout introducing a dependency on them? To solve this problem we can refinethe Model-View-Controller pattern with thePublisher-Subscriberpattern:

通过发布/订阅模式,在不引入依赖关系的前提下实现将model的修改通知到所有视图对象

OOD架构设计模式中MVC与ECB_第8张图片

 



你可能感兴趣的:(软件工程)