Student_Answers_Chapter_08

上传人:鲁** 文档编号:487728108 上传时间:2022-10-24 格式:DOC 页数:10 大小:65.50KB
返回 下载 相关 举报
Student_Answers_Chapter_08_第1页
第1页 / 共10页
Student_Answers_Chapter_08_第2页
第2页 / 共10页
Student_Answers_Chapter_08_第3页
第3页 / 共10页
Student_Answers_Chapter_08_第4页
第4页 / 共10页
Student_Answers_Chapter_08_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《Student_Answers_Chapter_08》由会员分享,可在线阅读,更多相关《Student_Answers_Chapter_08(10页珍藏版)》请在金锄头文库上搜索。

1、Suggested answer for Exercise 8.1(a) The instanceOf stereotypes are only shown here for illustration. The fact that the objects are instances of the Position class is already shown in the label of each object. (b) We assume that the counter maintains a single integer value, which is initialized to z

2、ero. Set and reset have the same effect, and so are modelled as a single operation, setToZero. (c) An enumeration is used below to specify the possible states of the switch. In this particular case, a Boolean state variable could be used, but defining an enumeration gives greater scope for extensibi

3、lity. Alternatively, the class interface could be specified without specifying how the state is recorded. (d) An attribute with many multiplicity is used below to record the set of illuminated lights, using the Colour enumeration illustrated in Figure 8.3. The OCL notation for collection literals ha

4、s been used to show the values of this attribute in the object icon. Suggested answer for Exercise 8.2(a) A person can have zero or more books out on loan, and each book can be borrowed by at most one person at any given time. (b) A person can have read many books, and each book may have been read b

5、y many people. (c) A piece can only occupy one square at a time, and if it has been captured, it occupies no square. Each square can have at most one piece on it. If the aim is to model only pieces on the board, the multiplicity at the right of this association should be exactly 1. (d) The multiplic

6、ities below refer to who is married to whom at a given time, assuming no polygamy or polyandry. As the spouse relation is symmetric, it can simply be labelled with an association name. (e) A person can have zero or more children, but each person has exactly two (biological) parents. This relation is

7、 not symmetric, so adding role names makes the intended interpretation clearer. Suggested answer for Exercise 8.7The job titles and salaries can most naturally be modelled by attributes in the Contract class, as shown in the diagram below. Suggested answer for Exercise 8.9If the abstract draw operat

8、ion was omitted from the Shape class, it would be impossible to invoke the draw operation on a shape without knowing what subclass it belonged to. In other words, code such as the following would not work: Shape s = new Rectangle() ;s.draw() ;It would be necessary to cast the object to its specific

9、subclass first: Shape s = new Rectangle() ;(Rectangle) s).draw() ;This would frustrate a major benefit of using generalization, namely the ability to abstract from the specific runtime class of objects and manipulate them through a common interface defined in a superclass. It is not really a failure

10、 of substitutability, as instances of subclasses such as Rectangle are still substitutable for instances of Shape. However, once this is done, they can only be manipulated through the shared interface defined in the Shape class. The principle required is that abstract superclasses must define all th

11、e operations in the interface shared by all their subclasses. Suggested answer for Exercise 8.10The association as written does not have the properties of antisymmetry and transitivity specified. The relationship being modelled, that between parents and children, is antisymmetric, as nobody can be t

12、heir own parent. The relationship is not transitive, however: the fact that the relationship of parent holds between your grandmother and your mother, and also between your mother and you does not mean that it holds between your grandmother and you. As the relationship is not transitive, it would be

13、 misleading to make the association in Figure 8.20 into an aggregation. Suggested answer for Exercise 8.11The class diagram is shown below. Note that only the classes linked by compositions are nested. Simple aggregations do not have the lifetime dependency of composites, and must still be shown as

14、associations. Object diagrams based on this reflect the same structure, as shown below. Suggested answer for Exercise 8.12The object diagram below shows a port on one computer connected to the processor of another. Suggested answer for Exercise 8.13The diagram in Figure 8.44 does not place any restr

15、ictions on the number of student or modules a given Attempt instance is related to. It would be consistent with the diagram to have an Attempt object that was not linked to any student, for example, and also to have one that was linked to more than one student. In the latter case, however, it would

16、have also to be linked to more than one module, as any given attempt and module objects can be linked to at most one student. There is no easy way of imposing the required multiplicity restrictions on this relationship when it is expressed as an n-ary association. Phenomena like this explain why in practical modelling, the overwhelming majority of associations used are bina

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 幼儿/小学教育 > 小学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号