4、GRASP原则四:控制器 Controller
   What first object beyond the UI layer receives and co-ordinates (controls) a system operation?

    在领域层,由谁负责首先接收并协调来自UI层的系统操作?
4.1 Mini Exercise 4

   For Monopoly game, Which object starts the game?
   Understanding the Problem

     SSD — boundary between the User and SUD (system under development)

     UI layer “catches” the request

     The request is a system operation — public interface

     Model-View Separation principle says UI must not contain business logic

     Problem: UI应该把捕捉到的系统操作,发给领域层的哪个对象呢?
4.2 GRASP rule4: Controller

   Name: Controller 控制器

   Problem:

     What first object beyond the UI layer receives and co-ordinates (controls) a system operation

   Solution:

     Assign the responsibility to a class representing one of the following choices:

     1. Facade(外观) Controller:

       represents the overall system, a root object, a device that the object is running within, or a major sub-system

     2. Use Case or Session Controller(用例控制器、会话控制器):

       represents a use case scenario within which the system event occurs
4.5 Controller — Observations 观察

   委托模式 Delegation pattern

   外部输入事件可以来自参与者(人)或者(其他系统)

   Facade — 相当于领域层对外部世界的“脸”

     Ex: Register

   Handler —处理系统某个明确的功能集,比如相关的一组系统事件

     Ex: ProcessSale
4.5 Controller — Facade

   外观控制器 Facade

     为子系统中的一组接口提供一个一致的界面

      Provide a consistent interface for a set of interfaces in subsystem“cover” over the other layers of the application

     Abstraction of an overall physical unit

       — Register, PizzaShop

     The entire software system

       — POSSystem

     Abstraction of some other overall system or sub-system concept

       — MonopolyGame

   适用于

     相对较小的系统 relatively small systems

     有限数量的系统操作 and/or system with limited number of system operations

     在消息处理系统中,不能转发消息到可选的控制器时

      in message handling system when can’t direct messages to alternative controllers

       — Internet application servers
4.5 Controller -- Session

   会话控制器

     一种纯虚构出来的概念 Pure Fabrication,即领域模型中没有的概念

     如, ProcessSaleHandler is not a domain concept in Domain Model

   会话控制器的应用场合

     当采用外观控制器会导致高耦合、低内聚时 When assigning to facade may lead to high coupling or low cohesion (“Bloat”)

     很多系统事件跨越多个不同的处理过程 Many system operations across different processes

     概念上容易理解和构建 Conceptually easier to understand and build

       一个会话控制器负责一类系统事件

   会话控制器的命名习惯 Session Controllers Naming conventions

       <UseCaseName> Handler or

       <UseCaseName> CoOrdinator or

       <UseCaseName>Session

     Use same controller class for all system operations in the use case scenario

     Session is a type of conversation between the actor and the SUD 新系统
4.7 Discuss: Controller — Benefits

   控制器模式的优点

     容易适应UI层的变化 Allows for easy change of UI and/or alternative UI

     领域层代码易于重用(因为UI层一般与应用关系密切)Allows for reuse of domain layer code (UI is usually application specific)

     有助于保证应用所需要的操作顺序 Helps ensure sequence of operation which may differ from UI input

     可以对系统的状态进行推理(UI层不保存系统状态)Can reason about system state — UI does not preserve state
4.8 Bloated(臃肿的) Controllers

   臃肿控制器的问题

     当一个外观控制器处理了大部分系统事件时 When have a facade controller handling all of many system events

     当一个控制器做了太多的事情,而不是委托给其他的对象去处理

      When the controller performs many of the system operations instead of delegating

     当控制器掌握了太多的系统信息 When the controller has many attributes (much information) about the system

       which should be distributed to or duplicates from elsewhere

     导致:低内聚 Low cohesion — 做事不专注,做了太多的事

   臃肿控制器的解决方法

     增加更多的控制器 Add more controllers

     采用会话控制器替换外观控制器 “session controller” instead of facade

     控制器委托任务给别的对象,而不是自己做 Design the controller so that it delegates operations to other objects

     高内聚的理念 High Cohesion is itself a GRASP principle

7.4 GRASP原则四:控制器 Controller的更多相关文章

  1. 运用GRASP原则来做uml交互类图-------pos机实例

    重要的几个GRASP原则:1.控制器模式   2.创建者模式 (原则)3.信息专家模式(原则) 4. 高内聚 低耦合   这里所说的模式并不是java中针对具体的事件的设计模式 主成功场景的几个操作: ...

  2. 7.6 GRASP原则六: 多态 Polymorphism

    GRASP原则六: 多态 Polymorphism  How to handle alternative behaviors based on type 如何处理依据类型不同而有 不同行为的一类需求 ...

  3. 7.1 通用的职责分配软件原则 GRASP原则一: 创建者 Creator

    1.GRASP原则一: 创建者 Creator  Who should be responsible for creating a new instance of some class 由谁来负责创 ...

  4. C#-MVC基础-模型(Model)、视图(View)和控制器(Controller)

    搜狗百科:http://baike.sogou.com/v25227.htm?fromTitle=MVC MVC全名是Model View Controller,是软件工程中的一种软件架构模式,把软件 ...

  5. 从零开始学习 asp.net core 2.1 web api 后端api基础框架(四)-创建Controller

    原文:从零开始学习 asp.net core 2.1 web api 后端api基础框架(四)-创建Controller 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...

  6. ASP.NET MVC5基础-控制器(Controller)详解

    在上文ASP.NET MVC5基础 – MVC文件架构中我们简单了解了下控制器Controller的作用,本文我将详细介绍控制器Controller的使用方法. Controller的运行过程 上文我 ...

  7. Spring MVC(四)--控制器接受pojo参数

    以pojo的方式传递参数适用于参数较多的情况,或者是传递对象的这种情况,比如要创建一个用户,用户有十多个属性,此时就可以通过用户的pojo对象来传参数,需要注意的是前端各字段的名称和pojo对应的属性 ...

  8. spring自动扫描、DispatcherServlet初始化流程、spring控制器Controller 过程剖析

    spring自动扫描1.自动扫描解析器ComponentScanBeanDefinitionParser,从doScan开始扫描解析指定包路径下的类注解信息并注册到工厂容器中. 2.进入后findCa ...

  9. Angularjs在控制器(controller.js)的js代码中使用过滤器($filter)格式化日期/时间实例

    Angularjs内置的过滤器(filter)为我们的数据信息格式化提供了比较强大的功能,比如:格式化时间,日期.格式化数字精度.语言本地化.格式化货币等等.但这些过滤器一般都是在VIEW中使用的,比 ...

随机推荐

  1. C#中的一些基础

    值类型与引用类型 值类型包括:[基本数据类型,如int,double,char,bool等][枚举类型enum][结构类型struct] 引用类型包括:[类类型,如基类Object,字符串类Strin ...

  2. poi导入excel表格数据到数据库的时候,对出生日期的校验

    出生日期格式为8位数字的字符串 如:yyyyMMdd 规则:yyyy大于1900并小于当前时间,月.日 按日期规则校验 //解决读过来的字符串显示为科学计数法问题 BigDecimal bd = ne ...

  3. Python递归函数介绍

    一.递归的定义 1.什么是递归:在一个函数里在调用这个函数本身 2.最大递归层数做了一个限制:997,但是也可以自己限制 # 验证 997 def foo(n): print(n) n+=1 foo( ...

  4. Spring的bean管理(注解方式)

    注解:代码中的特殊标记,注解可以使用在类.方法.属性上面,使用注解可实现一些基本的功能.注解的写法是@注解名称(属性=属性值). 使用注解创建对象 第一步,创建Web项目,引入Spring的开发包 第 ...

  5. python线程、协程、I/O多路复用

    目录: 并发多线程 协程 I/O多路复用(未完成,待续) 一.并发多线程 1.线程简述: 一条流水线的执行过程是一个线程,一条流水线必须属于一个车间,一个车间的运行过程就是一个进程(一个进程内至少一个 ...

  6. day014 模块

    # 1.用于多种语言交互 编程语言通用数据 # 内置的 不需要安装 直接导入使用 import json # 导入一个json模块 # dumps loads# dump load 有持久化的功能 # ...

  7. 基于Spark Streaming + Canal + Kafka对Mysql增量数据实时进行监测分析

    Spark Streaming可以用于实时流项目的开发,实时流项目的数据源除了可以来源于日志.文件.网络端口等,常常也有这种需求,那就是实时分析处理MySQL中的增量数据.面对这种需求当然我们可以通过 ...

  8. centos----------centos下安装谷歌浏览器

    1.首先你已经安装了带有可视化界面的centos系统. 2.打开里面自带的一个浏览器,输入网址 http://chrome.richardlloyd.org.uk/install_chrome.sh ...

  9. vue-awesome-swiper组件不能自动播放和导航器小圆点不显示问题

    from: https://blog.csdn.net/osdfhv/article/details/79062427 <template> <div class="swi ...

  10. Bugku-CTF之域名解析(听说把 flag.baidu.com 解析到123.206.87.240 就能拿到flag)

    Day 7 域名解析 50 听说把 flag.baidu.com 解析到123.206.87.240 就能拿到flag