《类图对象包图》PPT课件.ppt
《《类图对象包图》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《类图对象包图》PPT课件.ppt(175页珍藏版)》请在三一办公上搜索。
1、第五章 类图、对象图、包图,计算机科学学院 董兆安,Page 2,内容提要,类图由类以及类之间的关系组成。类图是所有面向对象建模方法的核心部分。类图描述了系统的静态结构。类可以表示程序设计中的一个类型。也可以表示现实世界的一类事物或概念。信息系统开发的各个阶段都要使用UML中的类图。在系统开发的不同阶段,类图表示了不同层次的抽象。概念层(Conceptual):在需求分析阶段,类图主要用于领域内的一些概念类的描述,形成概念模型;规格说明层:(Specification):在设计阶段,类图着重描述类与类之间的接口等外部特性,形成设计模型;实现层(Implementation):在实现阶段,类图主
2、要用于描述类的在软件系统中的内部实现。,Page 3,Classifiers(类目、分类器),A classifier is a mechanism that describes structural and behavioral features.Classifiers include classes,associations,interfaces,data types,signals,components,nodes,use cases,and subsystems.,Page 4,类(Classes),A class is a collection of things or concep
3、ts that have the same characteristics.Each of these things or concepts is called an object.类是具有相同特征(属性)和行为(方法)的对象的集合。a class describes a group of objects with:similar properties(attributes)common behavior(operation,method)common relationships to other objects common meaningclass diagrams show classe
4、s with their attributes and operations,together with the associations between classes,Page 5,describing a class,The level of detail you choose to show for your classes depends on who is reading the diagrams on which they appear.For example,a stakeholder whos focused on the big picture is probably in
5、terested only in the names of the classes,while a developer working at a more detailed level probably wants to see a full set of attributes and operations.,Page 6,简化表示(Icon Notation),Some models representations can be switched between Icon Notation and Class Notation.,Page 7,类的名称(Class names),UML中的名
6、称是标识某个模型元素的字符串。简单名(simple name):字母、数字和下划线的序列,通常以字母开始。复合名(path name):以分隔符分开的一个或者多个简单名的组合序列。例如:java:awt:Rectangle;java:util:Date 复合名称中的最后一个一般指某个实体,如:类或者用例。虽然UML具有非常宽松的命名规定,许多标点都可以使用。但是为了避免混乱,我们还是建议采用简单名称的命名约定,尽量使用字母、数字、下划线构成字符串的命名方式。在分析和设计的不同阶段,类的图符可以使用恰当的精简方式,省略一些细节,甚至属性、方法两个要素都可省略。但是类的名称是三个要素中,必须具备的
7、要素,不可以省略。,Page 8,属性 attribute,The full form of a UML attribute declaration is as follows:visibility name:type multiplicity=default-value property-string,visibilityNametypemultiplicitydefault-valueproperty-string,+(public),#(protected),-(private)e.g.CustomerName,DiscountRatee.g.Point,String,Date,etc.
8、e.g.0.1,2.*e.g.=(0,0),=nullchangeable(default),addOnly,frozen,6 examples of legal attribute declarationsoriginorigin:Point=(0,0)+originid:integer frozenorigin:Pointname:0.1:String,Page 9,可见性,visibility:The UML supports the following four levels of visibility:Package visibility(shown with a tilde)mea
9、ns that objects belonging to any class in the same package can see and use the given class it.Public visibility(+)means that objects belonging to any class can use the given attribute or operation.Protected visibility(#)means that only objects that belong to subclasses of the given class(at any leve
10、l below that class)can use the attribute or operation.(Subclasses are discussed in Chapter 2.)Private visibility(-)means that only objects belonging to the class itself can use the attribute or operation.,Page 10,visibility,When you specify the visibility of a classifiers features,you generally want
11、 to hide all its implementation details and expose only those features that are necessary to carry out the responsibilities of the abstraction.Thats the very basis of information hiding.,Page 11,属性的类型,type:Examples of built-in attribute data types include Double,Int(short for Integer),and String.An
12、attribute type can also be a user-defined type or the name of a class.,Page 12,多重性(Multiplicity),Multiplicity indicates how many of one thing can exist relative to another thing.A multiplicity value on an attribute indicates how many instances of that attribute are present for each instance of the c
13、lass.A multiplicity expression can take several forms,including the following:A fixed value(such as 1 or 3)An asterisk(*),which means manyA range of values,expressed as lower.upper(for instance,0.1 or 3.*)A set of values(for example,1,3,5,7),Page 13,an example,An object belonging to the Account clas
14、s can have from one to three email addresses.Each Account object has an ID that cant be deleted;you might think of this as being the equivalent of the key within a database table.And,theres an initial value for an Account objects password,which the Customer is likely to change but which is useful in
15、 case the Customer forgets to define a password when he or she sets up an Account.,Page 14,operation signatures 操作签名,The full form of a UML operation declaration is as follows:visibility name(parameter-list):return-typeThe parameters of an operation,which appear in a list separated by commas,represe
16、nt the data provided by the caller of the operation,the data that the operation returns to the caller,or both.,visibilitynameparameter-listreturn-type,+(public),#(protected),-(private)e.g.restart,addStudentsee next pagee.g.Integer,String,etc,Page 15,parameter declaration 参数声明,The full form of a para
17、meter declaration is as follows:direction name:type multiplicity=default-value A parameter can have one of the following three directions:in(The operation cant modify the parameter,so the caller doesnt need to see it again.)out(The operation sets or changes the value of the parameter and returns it
18、to the caller.)inout(The operation uses the value of the parameter and may change the value;the caller expects to see an inout parameter again.),directionnametypedefault-value,in,out,inoute.g.getId,calculateBonusBoolean,Money,etc.e.g.42,John,Page 16,an example,The checkAvailability operation receive
19、s a Book object and returns a value of the user-defined type OrderStatus.The isFulfilled operation is a query that returns True if everything the customer ordered is in place or False otherwise.,The UML defines a separate language,called the Object Constraint Language(OCL),that you can use to specif
20、y constraints.,Page 17,Note,对象约束语言简称OCL(Object Constraint Language),它是一种用于施加在指定的模型元素上约束的语言。Using the OCL enables you to reach a certain level of rigor in your modeling without side effects.In other words,the evaluation of OCL expressions cant alter the state of the executing system.对象约束语言是一种形式化语言,它主
21、要用于表示UML模型中施加于模型上的约束。OCL表达式以附加在模型元素上的条件和限制来表现对该对象的约束,其中包括附加在模型元素上的不变量或约束的表达式,附加在操作和方法上的前置条件和后置条件等。Two kinds of constraints are of particular interest in the context of operations:preconditions and postconditions.,Page 18,NOTE,Abstract:把一个类名写为斜体表示是抽象的;leaf,表示它是叶子操作,意味着该操作不是多态的,不可以被覆写(这类似于java中的final操
22、作)。除了leaf之外,还有:查询(query),操作不会改变系统的状态;顺序(sequential),调用者必须在对象外部进行协调;监护(guarded),通过将所有对象监护操作的所有调用顺序化;并发(concurrent),静态(static);,Page 19,responsibilities,职责指的是类所担任的任务,类的设计要完成什么样的功能,要存担的义务。一个类可以有多种职责,设计得好的类一般至少有一种职责,在定义类的时候,将类的职责分解成为类的属性和方法。类的职责其实只是一段或多段文本描述。通常在UML中在类图的最下方用单独的部分列出类的职责。Its often desirabl
23、e to define explicit responsibilities for a class.These represent the obligations that one class has with regard to other classes The idea of assigning responsibilities to classes is at the center of Class-Responsibility-Collaboration(CRC)cards.This idea is also central to Responsibility-Driven Desi
24、gn.,Page 20,UML object notation,The notation for an object takes the same basic form as that for a class.There are three differences between the notations,as follows:Within the top compartment of the class box,the name of the class to which the object belongs appears after a colon.The object may hav
25、e a name,which appears before the colon,or it may be anonymous,in which case nothing appears before the colon.The contents of the top compartment are underlined for an object.Each attribute defined for the given class has a specific value for each object that belongs to that class.,Page 21,classes a
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 类图对象包图 对象 PPT 课件
![提示](https://www.31ppt.com/images/bang_tan.gif)
链接地址:https://www.31ppt.com/p-5565934.html