初读了《UML和模式应用》收获很大,最重要的事这本书能教你了什么是OOA/D的思想,怎么认识对象,以及UML的威力。

UML作为模式语言用于设计和思考。

如何赋予对象的职责:

Doing responsibilities of an object include:
o doing something itself, such as creating an object or
doing a calculation
o initiating action in other objects
o controlling and coordinating activities in other objects

Knowing responsibilities of an object include:
o knowing about private encapsulated data
o knowing about related objects
o knowing about things it can derive or calculate

Responsibilities are implemented using methods
that either act alone or collaborate with other methods and objects

一个职责的实现或者是单独完成,或者是通过和其他对象协作来完成。

从uml交互图的创建中发掘对象职责:

Within the UML artifacts, a common context where these
responsibilities (implemented as methods) are considered is during the creation
of interaction diagrams。

GRASP九种pattern:

1、 Information Expert:分析对象知道什么--know what,即Expert Information Pattern,对象掌握了什么信息,就隐含了它应有何种职责。
2、 Creator:创建者

如果存在以下的关系:

. B aggregates A objects.
. B contains A objects.
. B records instances of A objects.
. B closely uses A objects.
. B has the initializing data that will be passed to A when it is created (thus B
is an Expert with respect to creating A).
B 就是A的一个创建者.B因此就具有创建的职责。

By expert information principle, sometimes a creator is found by looking for the class that has the initializing
data that will be passed in during creation。

3、 Low Coupling:低耦合

常见的耦合关系:

1).TypeX has an attribute (data member or instance variable) that refers to a TypeY instance, or TypeY itself.
2). A TypeX object calls on services of a TypeY object.
3). TypeX has a method that references an instance of TypeY, or TypeY itself, by any means. These typically include a parameter or local variable of type TypeY, or the object returned from a message being an instance of TypeY.
4).TypeX is a direct or indirect subclass of TypeY.

5).TypeY is an interface, and TypeX implements that interface.

Low Coupling encourages assigning a responsibility so that its placement does
not increase the coupling to such a level that it leads to the negative results that
high coupling can produce.
Low Coupling supports the design of classes that are more independent, which
reduces the impact of change. It can’t be considered in isolation from other patterns
such as Expert and High Cohesion, but rather needs to be included as one of
several design principles that influence a choice in assigning a responsibility.

4、 High Cohesion:高内聚

As a rule of thumb, a class with high cohesion has a relatively small number of
methods, with highly related functionality, and does not do too much work. It
collaborates with other objects to share the effort if the task is large.
A class with high cohesion is advantageous because it is relatively easy to maintain,
understand, and reuse. The high degree of related functionality, combined
with a small number of operations, also simplifies maintenance and enhancements.
The fine grain of highly related functionality also supports increased
reuse potential.

Bad cohesion usually begets bad coupling, and vice versa

类比于现实生活中,如果一个人承担太多职责,事情可能都办不好,很多经理不知道委任和放权,承担太多不需要自己承担的职责,结果搞得焦头烂额。要懂得委任和放权。

Modular Design:

We promote a modular design by creating methods and classes with high cohesion.
At the basic object level, modularity is achieved by designing each method
with a clear, single purpose, and grouping a related set of concerns into a class。

5、 Controller:使用controller接收和处理系统事件,Controller定义系统操作。

怎样创建 Domain Model:

Apply the following steps to create a domain model:

a.  List the candidate conceptual classes using the Conceptual Class Category
b. List and noun phrase identification techniques related to the current
    requirements under consideration.
b. Draw them in a domain model.
c.  Add the associations necessary to record relationships for which there is a  
     need to preserve some memory (discussed in a subsequent chapter).
d.  Add the attributes necessary to fulfill the information requirements (discussed
     in a subsequent chapter).

6. Polymorphism 多态

7. Indirection

8. Pure Fabrication

9. Protected Variations

发现Conceptual Class:

conceputal class 和属性的区别:

如果一个对象不是简单的number, string, boolean, date, time

,那么它就应该设计成一个类.

1、通过Conceptual Class Category表来检查所有的可能:

Conceptual Class Category Examples
physical or tangible objects Register Airplane
specifications, designs, or descriptions
of things
ProductSpecification
FlightDescription
places Store
Airport
transactions Sale, Payment
Reservation
transaction line items SalesLineItem
roles of people Cashier
Pilot
containers of other things Store, Bin
Airplane
things in a container Item
Passenger
other computer or electro-mechanical
systems external to the system
CreditPaymentAuthorizationSystem
AirTrafficControl
abstract noun concepts Hunger
Acrophobia
organizations SalesDepartment
ObjectAirline
events Sale, Payment, Meeting
Flight, Crash, Landing
processes
(often not represented as a concept,
,but may be)
SellingAProduct
BookingASeat
rules and policies RefundPolicy
CancellationPolicy
catalogs ProductCatalog
PartsCatalog
records of finance, work, contracts,
legal matters
Receipt, Ledger, EmploymentContract
MaintenanceLog
financial instruments and services LineOfCredit
Stock
manuals, documents, reference
papers, books
DailyPriceChangeList
RepairManual


2、从用例中提取名词作为conceptual class的候选:

Main Success Scenario (or Basic Flow):
1. Customer arrives at a POS checkout with goods and/or services to purchase.
2. Cashier starts a new sale.
3. Cashier enters item identifier.
4. System records sale line item and presents item description, price, and running
total. Price calculated from a set of price rules.
Cashier repeats steps 2-3 until indicates done.
5. System presents total with taxes calculated.
6. Cashier tells Customer the total, and asks for payment.
7. Customer pays and System handles payment.
8. System logs the completed sale and sends sale and payment information to the
external Accounting (for accounting and commissions) and Inventory systems (to
update inventory).
9. System presents receipt.
10.Customer leaves with receipt and goods (if any).
Extensions (or Alternative Flows):
7a. Paying by cash:
1. Cashier enters the cash amount tendered.
135
10 - DOMAIN MODEL: VISUALIZING CONCEPTS
2. System presents the balance due, and releases the cash drawer.
3. Cashier deposits cash tendered and returns balance in cash to Customer.
4. System records the cash payment.

设计Attributes原则:

1、Keep Attributes Simple

2、Attributes should generally be data types:见primative和non-primative datatype

3、No Attributes as Foreign Keys:不要用属性作为外键来关联两个对象,应该直接引用这个对象。

primative和non-primative datatype:

non-primative:

These data type values are also known as value objects.

It is composed of separate sections.
such as: phone number, name of person
?There are operations usually associated with it, such as parsing or validation.
such as: social security number
?It has other attributes.
such as: promotional price could have a start (effective) date and end
date
?It is a quantity with a unit.
such as: payment amount has a unit of currency
?It is an abstraction of one or more types with some of these qualities.
item identifier in the sales domain is a generalization of types
such as Universal Product Code (UPC) or European Article
Number (EAN)

These data type values are also known as value objects.

设定Associations:

1、运用Common Associations List

Category Examples
A is a physical part of B Drawer — Register (or more specifically,
a POST)
Wing — Airplane
A is a logical part of B SalesLineItem — Sale
FlightLeg—FlightRoute
A is physically contained in/on B Register — Store, Item — Shelf
Passenger — Airplane
A is logically contained in B ItemDescription — Catalog
Flight— FlightSchedule
A is a description for B ItemDescription — Item
FlightDescription — Flight
A is a line item of a transaction or report B SalesLineItem — Sale
Maintenance Job — Maintenance-
Log
A is known/logged/recorded/reported/captured
in B
Sale — Register
Reservation — FlightManifest
A is a member of B Cashier — Store
Pilot — Airline
A is an organizational subunit of B Department — Store
Maintenance — Airline
A uses or manages B Cashier — Register
Pilot — Airplane
A communicates with B Customer — Cashier
Reservation Agent — Passenger
A is related to a transaction B Customer — Payment
Passenger — Ticket
A is a transaction related to another transaction
B
Payment — Sale
Reservation — Cancellation
A is next to B SalesLineItem — SalesLineItem
City— City
A is owned by B Register — Store
Plane — Airline
A is an event related to B Sale — Customer, Sale — Store
Departure — Flight

Interaction diagrams (交互图):Sequence and Collaboration Diagrams

1.Sequence:

System Sequence Diagrams

System behavior
is a description of what a system does, without explaining how it does it. One
part of that description is a system sequence diagram. Other parts include the
use cases, and system contracts (to be discussed later).

2.Collaboration:

Collaboration diagrams illustrate object interactions in a graph or network
format, in which objects can be placed anywhere on the diagram

书中强调一定要重视交互图,花费更多的时间在交互图分析上,因为创建交互图是OOA/D中一个非常creative的步骤。it will provide a thoughtful, cohesive, common starting point for inspiration during programming.

Relatively speaking, the creation of use cases, domain models, and other artifacts is easier than the assignment of responsibilities and the creation of well-designed interaction diagrams.This is because there is a larger number of subtle design principles and "degrees of freedom" that underlie a well-designed interaction diagram than
most other OOA/D artifacts.

设计user case和domain model要比职责分配和创建良好的交互图要容易些。因为后者包含了大量的微妙的设计原则和设计自由度在里面。

ADDING DETAIL WITH OPERATION CONTRACTS

Use cases are the primary mechanism in the UP to describe system behavior,
and are usually sufficient. However, sometimes a more detailed description of
system behavior has value. Contracts describe detailed system behavior in
terms of state changes to objects in the Domain Model, after a system operation
has executed.

转载于:https://www.cnblogs.com/babykick/archive/2011/06/12/2078826.html

《UML和模式应用》读书笔记相关推荐

  1. 读书笔记 | 墨菲定律

    1. 有些事,你现在不做,永远也不会去做. 2. 能轻易实现的梦想都不叫梦想. 3.所有的事都会比你预计的时间长.(做事要有耐心,要经得起前期的枯燥.) 4. 当我们的才华还撑不起梦想时,更要耐下心来 ...

  2. 读书笔记 | 墨菲定律(一)

    1. 有些事,你现在不做,永远也不会去做. 2. 能轻易实现的梦想都不叫梦想. 3.所有的事都会比你预计的时间长.(做事要有耐心,要经得起前期的枯燥.) 4. 当我们的才华还撑不起梦想时,更要耐下心来 ...

  3. 洛克菲勒的38封信pdf下载_《洛克菲勒写给孩子的38封信》读书笔记

    <洛克菲勒写给孩子的38封信>读书笔记 洛克菲勒写给孩子的38封信 第1封信:起点不决定终点 人人生而平等,但这种平等是权利与法律意义上的平等,与经济和文化优势无关 第2封信:运气靠策划 ...

  4. 股神大家了解多少?深度剖析股神巴菲特

    股神巴菲特是金融界里的传奇,大家是否都对股神巴菲特感兴趣呢?大家对股神了解多少?小编最近在QR社区发现了<阿尔法狗与巴菲特>,里面记载了许多股神巴菲特的人生经历,今天小编简单说一说关于股神 ...

  5. 2014巴菲特股东大会及巴菲特创业分享

     沃伦·巴菲特,这位传奇人物.在美国,巴菲特被称为"先知".在中国,他更多的被喻为"股神",巴菲特在11岁时第一次购买股票以来,白手起家缔造了一个千亿规模的 ...

  6. 《成为沃伦·巴菲特》笔记与感想

    本文首发于微信公众帐号: 一界码农(The_hard_the_luckier) 无需授权即可转载: 甚至无需保留以上版权声明-- 沃伦·巴菲特传记的纪录片 http://www.bilibili.co ...

  7. 读书笔记002:托尼.巴赞之快速阅读

    读书笔记002:托尼.巴赞之快速阅读 托尼.巴赞是放射性思维与思维导图的提倡者.读完他的<快速阅读>之后,我们就可以可以快速提高阅读速度,保持并改善理解嗯嗯管理,通过增进了解眼睛和大脑功能 ...

  8. 读书笔记001:托尼.巴赞之开动大脑

    读书笔记001:托尼.巴赞之开动大脑 托尼.巴赞是放射性思维与思维导图的提倡者.读完他的<开动大脑>之后,我们就可以对我们的大脑有更多的了解:大脑可以进行比我们预期多得多的工作:我们可以最 ...

  9. 读书笔记003:托尼.巴赞之思维导图

    读书笔记003:托尼.巴赞之思维导图 托尼.巴赞的<思维导图>一书,详细的介绍了思维发展的新概念--放射性思维:如何利用思维导图实施你的放射性思维,实现你的创造性思维,从而给出一种深刻的智 ...

  10. 产品读书《滚雪球:巴菲特和他的财富人生》

    作者简介 艾丽斯.施罗德,曾经担任世界知名投行摩根士丹利的董事总经理,因为撰写研究报告与巴菲特相识.业务上的往来使得施罗德有更多的机会与巴菲特亲密接触,她不仅是巴菲特别的忘年交,她也是第一个向巴菲特建 ...

最新文章

  1. 【C/C++】中的__FILE__、__LINE__、#line、__func__关键字(预定义宏)
  2. openssl简介-指令asn1parse
  3. docker,containerd,runc,docker-shim之间的关系
  4. 北京内推 | ​百度自然语言处理部内容理解方向招收NLP算法实习生
  5. 《Java 核心技术卷1 第10版》学习笔记------异常
  6. H.264 中很有用的一些概念
  7. 基于 CODING 的 Spring Boot 持续集成项目
  8. Qt文档阅读笔记-ToolBar QML Type
  9. 可折叠的 iPhone 要来了?
  10. c++11特性与cocos2d-x 3.0之std::bind与std::function
  11. 多头注意力比单头好在哪?
  12. dnf服务器字幕乱码win10系统,主编帮你win10系统玩dnf字体模糊的方案
  13. 网页设计作业-HTML5+CSS大作业——端午节日(25页) 图片滚动
  14. Win10下用Strokeit的方法
  15. Android实现仿制手机卫士的一键加速的百分框
  16. Bitwise Operation
  17. java案例--根据规则验证身份证号码正确性
  18. yyt_hac站转的 有关 木马及进程的 文章
  19. 以太坊源码分析(9)CMD实际操作分析
  20. 表情包生成1.0安卓版 斗图永无止尽

热门文章

  1. find的用法(完整)
  2. 游戏系统开发设计分享
  3. webpack css loader
  4. php神盾解密工具 注册码_教你如何解密 “ PHP 神盾解密工具 ”
  5. This old-style function definition is not preceded by a prototype
  6. [git] your branch is ahead of ... 解决办法
  7. js 正则解决密码必须包含数字+特殊字符+英文字母大小写
  8. pdf的下载和在线预览
  9. TorontoCity:众生观天下
  10. Mysql日期的加减法_mysql日期加减