Modeling the Vocabulary of a System
为系统的词汇表建模
You’ll use classes most commonly to model abstractions that are drawn from the problem you are trying to solve or from the technology you are using to implement a solution to that problem. Each of these abstractions is a part of the vocabulary of your system, meaning that, together, they represent the things that are important to users and to implementers.
你可以使用最常用的类为抽象建模,这些抽象来自你正在尝试解决的问题或是使用实现一个解决这个问题的技术.这些抽象的每一个都是系统词汇的一部分.同时这意味着,它们代表的是那些对用户和实施者很重要的事情.
For users, most abstractions are not that hard to identify because, typically, they are drawn from the things that users already use to describe their system. Techniques such as CRC cards and use case-based analysis are excellent ways to help users find these abstractions. For implementers, these abstractions are typically just the things in the technology that are parts of the solution.
对用户来说,大多数的抽象事物并不难识别,因为,通常它们来自用户在描述它们的系统时已经使用过的事物.像CRC卡技巧和基于用例分析的技巧都是帮助用户寻找这些抽象事物的很好的方法.对于实施者来说,这些抽象事物,通常仅是技巧的一部分.
To model the vocabulary of a system,
为构建系统的词汇表,需要做的事有:
1.Identify those things that users or implementers use to describe the problem or solution. Use CRC cards and use case-based analysis to help find these abstractions.
识别那些用户和实施者使用描述问题和答案的事物.使用CRC卡和基于用例分析来帮助寻找这些抽象.
2. For each abstraction, identify a set of responsibilities. Make sure that each class is crisply defined and that there is a good balance of responsibilities among all your classes.
为每个抽象标识一组职责.确保每个类清晰地被定义,这能很好的平衡你所有类之间的职责.
3. Provide the attributes and operations that are needed to carry out these responsibilities for each class.
为每个需要执行这些职责的类提供属性和操作.
Figure 4-9 shows a set of classes drawn from a retail system, including Customer, Order, and Product. This figure includes a few other related abstractions drawn from the vocabulary of the problem, such as Shipment(used to track orders), Invoice(used to bill orders), and Warehouse(where products are located prior to shipment). There is also one solution-related abstraction, Transaction, which applies to orders and shipments.
如图4-9显示的一组来自零售系统的类,包括客户,订单,和产品.这个图包含少量来自问题词汇表的其它相关抽象,如发货(用来跟踪订单),发票(用于已支付订单),和仓库(定义发货之前产品的位置).还有一个解决方案相关的抽象:交易,它适用于订单和发货.
As your models get larger, many of the classes you find will tend to cluster together in groups that are conceptually and semantically related. In the UML, you can use packages to model these clusters of classes.
当你的模型越来越大时,你会发现更多的类将趋向于聚集在概念上和语义相关的群中.在UML中,你可以使用包来构建这些类的聚集.
Your models will rarely be completely static. Instead, most abstractions in your system’s vocabulary will interact with one another in dynamic ways. In the UML, there are a number of ways to model this dynamic behavior.
你的模型很少会是完全静态的.相反,在你的系统词汇表中大多数的抽象将会以动态的方式互相影响.在UML中,有一些构建这些动态行为的方法.