可低内聚的场合 e grouping of responsibilities or code into one class or component to simplify maintenance by one person 只有1,2个SQL专家,对OO不熟 o software architect may decide to group all the SQL statements into one class, RDBOperations
可低内聚的场合 grouping of responsibilities or code into one class or component to simplify maintenance by one person ⚫ 只有1,2个SQL专家,对OO不熟 ⚫ software architect may decide to group all the SQL statements into one class, RDBOperations
可低内聚的场合2 e distributed server objects less remote calls, and better performance 远程服务器对象要 fewer and larger, less cohesive,为很 多操作提供接口 ●远程操作粗粒度,以便次 remote operation ca可以做或 请求更多的工作 o Example 1: remote object with three fine grained operations/setName, setSalary, and sethire Date EXample 2: one remote operation setData which receives a set of data Which is better?
可低内聚的场合2 distributed server objects ⚫ less remote calls, and better performance. ⚫ 远程服务器对象要fewer and larger, less cohesive,为很 多操作提供接口 ⚫ 远程操作粗粒度,以便一次remote operation call可以做或 请求更多的工作 ⚫ Example 1: remote object with three finegrained operations setName, setSalary, and setHireDate ⚫ Example 2: one remote operation setData which receives a set of data ⚫ Which is better?
五个 GRASP模式 Low Coupling High cohesion e. Controller Creator Information Expert
五个GRASP模式 . Low Coupling . High Cohesion . Controller . Creator . Information Expert
模式: Controller ● Problem:谁负责处理系统输入事件? Solution:将处理系统输入事件的职责分配给代 表以下的类 代表整个系统、设备或子系统-外观 Controller facade controller) 代表整个业务过程或组织( acade controller) ·代表现实世界中可能执行该任务的角色role controller) 代表系统事件发生的用例场景,(use- case or session controller)
模式:Controller Problem:谁负责处理系统输入事件? Solution:将处理系统输入事件的职责分配给代 表以下的类: ⚫ 代表整个系统、设备或子系统-外观Controller (facade controller) ⚫ 代表整个业务过程或组织(facade controller) ⚫ 代表现实世界中可能执行该任务的角色(role controller) ⚫ 代表系统事件发生的用例场景,(use-case or session controller)
Problem o the Ul domain layers should be loosely coupled e Which object should coordinate msgs between the Ul and other domain obiects? ● Solution( advice) o Assign responsibility to an object representing The systemor a root'object (Store, Bank) A device/subsystem(Accounting System, BankATM) A use case scenario GameHandler) Single channel of communication between layers
⚫ Problem: ⚫ The UI & domain layers should be loosely coupled ⚫ Which object should coordinate msgs between the UI and other domain objects? ⚫ Solution (advice): ⚫ Assign responsibility to an object representing.. ⚫ The ‘system’ or a ‘root’ object (Store, Bank) ⚫ A device/subsystem (AccountingSystem, BankATM) ⚫ A use case scenario (GameHandler) ⚫ ‘Single channel of communication between layers’