L14-S1Objects & Classes 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad,...
-
Upload
brett-barker -
Category
Documents
-
view
222 -
download
0
Transcript of L14-S1Objects & Classes 2003 SJSU -- CmpE Advanced Object-Oriented Analysis & Design Dr. M.E. Fayad,...
2003 SJSU -- CmpE L14-S1 Objects & Classes
Advanced Object-Oriented Analysis & Design
Dr. M.E. Fayad, Professor
Computer Engineering Department, Room #283I
College of Engineering
San José State University
One Washington Square
San José, CA 95192-0180
http://www.engr.sjsu.edu/~fayad
2003 SJSU – CmpE M.E. Fayad L14-S3 Objects & Classes
Lesson Objectives
Objectives
3
Overview of Previous Lecture
Explore Modeling Notation Understand Objects, Attributes, Operations, and Notes in UML
Discuss the following:
– Different Kind of Classes
– Class Diagrams
2003 SJSU – CmpE M.E. Fayad L14-S5 Objects & Classes
Real-world systems can be decomposed into discrete
entities called objects
Objects represent things, concepts, or abstraction with
definable boundaries and behaviors
An object is specific instance of a class to which it
belongs
Classes have attributes and behaviors
Individual objects have their own specific values for each
attribute and share the same behaviors
Objects & Classes (1)
5
2003 SJSU – CmpE M.E. Fayad L14-S6 Objects & Classes
Example Objects Classes Attributes
A computer screen Screen Resolution, # of colorsA window Window Size, location
IBM Company Name, location, total revenue
Joe Harris Employee Name, department, salary
Objects & Classes (2)
6
2003 SJSU – CmpE M.E. Fayad L14-S7 Objects & Classes
Objects & Classes (3)
Objects with the same attributes, behaviors, and relationships
are grouped together into classes
A class describes general attributes and behaviors for a group of
objects
An object is a single instance of its class (e.g., IBM is an
instance of the Company class)
A Class diagram is used to describe the attributes and behaviors
of a class
7
2003 SJSU – CmpE M.E. Fayad L14-S8 Objects & Classes
Classes (1)
Classes are the most important building block of any Classes are the most important building block of any
object-oriented systemobject-oriented system
A class is a description of a set of objects that share A class is a description of a set of objects that share
the same attributes, operations, relationships, and the same attributes, operations, relationships, and
semantics.semantics.
Graphically, a class is rendered as a rectangleGraphically, a class is rendered as a rectangle
8
2003 SJSU – CmpE M.E. Fayad L14-S9 Objects & Classes
Classes (2)
9
RegistrationForm
RegistrationManager
Course
Student
CourseOfferingProfessor
ScheduleAlgorithm
2003 SJSU – CmpE M.E. Fayad L14-S10 Objects & Classes
Naming & AttributesNaming & Attributes NamingNaming
Classes should be named using the vocabulary of the domainClasses should be named using the vocabulary of the domain
Naming standards should be created -- e.g., all classes are Naming standards should be created -- e.g., all classes are
singular nouns starting with a capital lettersingular nouns starting with a capital letter
AttributesAttributes
An attribute is a named property of a class that describes a An attribute is a named property of a class that describes a
range of values that instances of the property may holdrange of values that instances of the property may hold
10
2003 SJSU – CmpE M.E. Fayad L14-S11 Objects & Classes
Attributes
11
Each course offeringhas a number, location and time
CourseOffering
numberlocationtime
2003 SJSU – CmpE M.E. Fayad L14-S12 Objects & Classes
OperationsOperations
An operation is the implementation of a service that An operation is the implementation of a service that
can be requested from any object of the class to affect can be requested from any object of the class to affect
behaviorbehavior
12
RegistrationManager
addCourse(Student,Course)
2003 SJSU – CmpE M.E. Fayad L14-S13 Objects & Classes
ResponsibilityResponsibility
A responsibility is a contract or an obligation of a classA responsibility is a contract or an obligation of a class
13
RegistrationManager
Responsibility:-- manage the registration
process
2003 SJSU – CmpE M.E. Fayad L14-S14 Objects & Classes
Finding Classes
Where to find candidate classes:Where to find candidate classes:
o Nouns in descriptions or conversationNouns in descriptions or conversation
o Checklists of general/typical object typesChecklists of general/typical object types
o Similar computerized systemsSimilar computerized systems
o Technical literature in the problem domainTechnical literature in the problem domain
14
2003 SJSU – CmpE M.E. Fayad L14-S15 Objects & Classes
Example Classes
15
Phenomena Classes
Thing Car, goods, packaging, materials
People & roles Employee, parent, customer, member
Organizations Company, department, group, project
Places Shelf, parking spot, construction site, city
Concepts Square, currency, quality parameters, fee
Resources Money, time, energy, labor force, info
Apparatuses Radar, sensor, valve, motor
Systems Street register, cash register, alarm system
2003 SJSU – CmpE M.E. Fayad L14-S16 Objects & Classes
Evaluating Classes
Does the class contain unique information?Does the class contain unique information?
Does the class encompass multiple objects?Does the class encompass multiple objects?
Can we identify objects from the class?Can we identify objects from the class?
Does the class have a manageable number of Does the class have a manageable number of
operations?operations?
Does the class embodies a well-defined responsibility?Does the class embodies a well-defined responsibility?
16
2003 SJSU – CmpE M.E. Fayad L14-S17 Objects & Classes
17
Classes in UML (1)
Class AbstractClass
<<utility>>UtilityClass
attribute
operation()
<<Stereotype>>Package::Class{Constraints}
Syntax for attributes and operationsAttribute[Cardinality]:Package::Type = InitialValue {Constraints}Operation(ArgumentList):ReturnType {Constraints}
<<metaclass>>MetaClass
<<ActiveClass>>ActiveClass
2003 SJSU – CmpE M.E. Fayad L14-S18 Objects & Classes
18
Classes in UML (2)
ParameterizedClass
ParameterizedClass<Parameter>
i:Element
normalOperation()abstractOperation()/derivedOperation()
classOperation()publicOperation()
#protectedOperation()-privateOperation()
Class
normalAttribute/derivedAttribute
classAttributepublicAttribute
#protectedAttribute-privateAttribute
Class
2003 SJSU – CmpE M.E. Fayad L14-S19 Objects & Classes
Related Terms: Type
Definition: Class = Attributes + Operations
A class includes the definition of potential constraints, tagged values, and stereotypes.
Notation:
19
Classes in UML (3)
Class
attribute1attribute2
operation1()operation2()
Class
attribute1attribute2
Class
attribute1attribute2
Class
Class
operation1()operation2()
operation1()operation2()
Class
2003 SJSU – CmpE M.E. Fayad L14-S20 Objects & Classes
<< .. >> stereotype
{ .. } tagged values
:: separate package and class names
20
Classes in UML (4)
attribute: Type=InitialValue {Constraints}
operation(Paramter) {Constraints}
<<Stereotype>>Package::Class
{PropertyValues}
2003 SJSU – CmpE M.E. Fayad L14-S21 Objects & Classes
21
Classes in UML (5)
Circle
Class name
Attribute names
Attribute type
Operations
Class Example
Constraint
Initial value
Parameters(name: type = initial value)
radius {radius>0}centerpoint: Point = (10, 10)
display(0remove()
setPosition(pos: Point)setRadius(newRadius)
Graphics::Circle
Package name
2003 SJSU – CmpE M.E. Fayad L14-S22 Objects & Classes
In Smalltalk and CLOS, classes are simply objects, that is, classes can be sent messages, and they can include (class) attributes.
In C++, class attributes and operations can be emulated by declaring them as static.
However, in C++ classes cannot be treated like objects. An example for a class message or a class operation is new, which is used to create a new instance of a class.
In Smalltalk for example:
newObject := Class new;
anEmployee := Employee new;
Classes of class objects are called metaclasses and similarly to a normal class, noted with a stereotype <<metaclass>>
22
Classes in UML (6) - Metaclasses
<<metaclass>>CustomerClass
2003 SJSU – CmpE M.E. Fayad L14-S23 Objects & Classes
In UML, metaclass is a class describing itself or other classes.
In UML, class operations need not be noted within the metaclass; they may also be contained in the class itself, where they are underlined in order to distinguish them from normal operations.
23
Classes in UML (7) - Metaclasses
numInstance: Integername: String
birthDate: Date
new(name)age(): Integer
Person
numInstance: Integer
new(name)
<<metaclass>>PersonClass
<<instance of>>
2003 SJSU – CmpE M.E. Fayad L14-S24 Objects & Classes
Definition:
A parameterized class is a template equipped with generic formal parameters, which can be used to generate common (non-parameterized) classes.
The generic parameters serve as placeholders for the actual parameters which represent classes or simple data types.
Description:
In a parameterized class, no concrete class is defined, but only a template for generation of classes.
These templates are usually a type of macro technique which has no special function, apart from a text replacement.
In statically typed languages, parameterized classes are an important means for writing re-usable code.
C++ and Eiffel support parameterized classes. 24
Classes in UML (8) - Parameterized Classes
2003 SJSU – CmpE M.E. Fayad L14-S25 Objects & Classes
A class generated with the aid of a parameterized class is called a bound element.
Notation
25
Classes in UML (9) - Parameterized Classes
i:Element
WaitingQueue
add()remove()
TrafficJam
WaitingRoom
<<bind>> (Car)
<<bind>> (Patient)
WaitingQueue<Car>
2003 SJSU – CmpE M.E. Fayad L14-S26 Objects & Classes
Related Terms: virtual class
Definition:
– An Abstract class is never used to generate object instances.
– It is intentionally incomplete and thus forms the basis for further subclasses which can have instances.
Description:
Abstract classes often represent a general term, a generic term for a set of concrete terms.
Thus a vehicle can be an abstract generic term for bicycle, car, truck, train, and airplane.
Vehicle in this case is merely an abstraction, a generalization.26
Classes in UML (9) - Abstract Classes
2003 SJSU – CmpE M.E. Fayad L14-S27 Objects & Classes
An abstract class is always a superclass.
An abstract class that has no subclasses makes no sense. Either it is superfluous, or it lacks a concrete class as subclass.
Notation
27
Classes in UML (9) - Abstract Classes
Class{abstract}
attributes
Operations()
Class
attributes
Operations()
Class
Class{abstract}
2003 SJSU – CmpE M.E. Fayad L14-S28 Objects & Classes
Example
28
Classes in UML (9) - Abstract Classes
GeomFigure
Triangle Circle Rectangle
Abstract Class
Concrete Class
2003 SJSU – CmpE M.E. Fayad L14-S29 Objects & Classes
Utility classes are collections of global variables and functions which are combined into a class.
The stereotype <<utility>> marks a class as a utility class
Utility classes are not true classes, but collection of global variables and functions which are, however, noted in the form of a class.
In OO, they are usually not needed.
29
Classes in UML (9) - Utility Classes
sin(angle): Realcos(angle): Realtan(angle): Realcot(angle): Real
<<utility>>MathFun
2003 SJSU – CmpE M.E. Fayad L14-S30 Objects & Classes
30
Objects in UML (1)
Object : Class
attributeName = value
Object
:Class
ActiveObject
Multiobject
2003 SJSU – CmpE M.E. Fayad L14-S31 Objects & Classes
31
Objects in UML (2)
Related terms: instance Definition:
– An object is a unit which actually exists and acts in the current system.
– Each object is an instance of a class.
– An object contains information represented by the attributes whose structure is defined in the class.
– An object can receive the messages defined in the class, that is, it has appropriate operations for each message defined.
2003 SJSU – CmpE M.E. Fayad L14-S32 Objects & Classes
32
Objects in UML (3)
Description:
– An alternative term for object is instance.
– A class contains the definition of objects, that is, their abstract description.
– The behavior of an object is described through the possible messages it can understand.
– For each message, the object needs appropriate operations.
2003 SJSU – CmpE M.E. Fayad L14-S33 Objects & Classes
33
Objects in UML (4)
Notation– Objects are represented by rectangles which either
bear only their own name, or which in addition show the name of their class, or the values of specific or all attributes.
– If attribute values are indicated, the rectangle is divided into two sections, separated by a horizontal line.
– The name of the object is underlined, and usually begins with a lower case letter.
2003 SJSU – CmpE M.E. Fayad L14-S34 Objects & Classes
34
Objects in UML (5)
Example:
aCircle: Circle
Radius = 25Center = (10,10)
Instance name
Attribute names
Class name
Attribute values
2003 SJSU – CmpE M.E. Fayad L14-S35 Objects & Classes
35
Attributes in UML (1)
Related terms: data element, instance variable, variable, member
Definition:– An attribute is a (data) element which is
contained in the same way in each object of a class and is represented by each object with an individual value.
2003 SJSU – CmpE M.E. Fayad L14-S36 Objects & Classes
36
Attributes in UML (2)
Description: Each attribute is at least described by its name. In addition, a
data type or a class, plus an initial value and constraints may be defined.
Constraints can be used in addition to the type specification to further restrict the value range or value set of the attribute, or to make it dependent on other conditions.
Tagged values can be used to specify additional special properties. Thus, for example, the tagged value {readonly} indicates that an attribute may only be read.
2003 SJSU – CmpE M.E. Fayad L14-S37 Objects & Classes
37
Attributes in UML (3)
Notation:– Attribute names begin with lower-case characters and class
names with upper-case one, while tagged values and constraints are enclosed in braces
• attribute : Package::Class =
InitialValue {PropertyValue} {Constrant}
– Derived attributes are marked by a prefixed slash (/)
/derivedAttribute
classAttribute
+publicAttribute
#protectedAttribute
-privateAttribute
2003 SJSU – CmpE M.E. Fayad L14-S38 Objects & Classes
38
Attributes in UML (4)
Examples:
name: String = ‘Unknown’
invoiceDate : Date = today
birthDate : Date
color : {red, blue, green}
radius : Integer = 25 {readonly} {radius>0}
/numChildren {numChildren = childrenSet count}
/age {age = today - birthDate}
-counter : Integer
dynamicArray[*]
2003 SJSU – CmpE M.E. Fayad L14-S39 Objects & Classes
39
Operations, Methods in UML (1)
Related terms: method, service procedure, routine function, message
Definitions:– Operations are services which may be required from an object.
– They are described by their signature (operation name, parameters, and if needed, return type).
– A method implements an operation; it is a sequence of instructions.
– A message passes an object the information on the activity it is expected to carry out, thus requesting it to perform an operation.
2003 SJSU – CmpE M.E. Fayad L14-S40 Objects & Classes
Description– A message consists of a selector (a name) and a
list of arguments, and is directed to exactly one receiver.
– The sender of a message is as a rule returned exactly one response object.
– Inside a class definition, an operation has a unique signature composed of the name of the operation, potential parameters, and a potential return value (function result).
40
Operations, Methods in UML (2)
2003 SJSU – CmpE M.E. Fayad L14-S41 Objects & Classes
Description (continued)– Operations may be provided with constraints which
can describe the conditions to be met at the call or the values the arguments may have, among other things.
– Tagged values can be used to describe additional special features. Some tagged values are:
• {abstract} to indicate an abstract operation
• {obsolete} to indicate that this operation exists only for compatibility with previous versions.
41
Operations, Methods in UML (3)
2003 SJSU – CmpE M.E. Fayad L14-S42 Objects & Classes
Notation– The signature of an operation is given as
follows:• name(argument : ArgumentType = DefaultValue, …):
ReturnType {PropertyValues} {Constraints}
– Example:• setPosition(x : Integer = 1, y : Integer =1):
Boolean {abstract} {(x > 0) and (y > 0)}
42
Operations, Methods in UML (4)
2003 SJSU – CmpE M.E. Fayad L14-S43 Objects & Classes
Naming Conventions– Be extremely careful with the naming of
operations. You should be conscious of what the operation is supposed to do and for which outcomes it is responsible.
– Always try to use active verbs, be careful with adjectives, and be precise!
43
Operations, Methods in UML (5)
2003 SJSU – CmpE M.E. Fayad L14-S44 Objects & Classes
Related terms: usage context, constraint Definition:
– Stereotypes are project-, enterprise-, or method-specific extensions of pre-existing model elements of the UML metamodel. According to the semantics defined with the extension, the model element to which the stereotype is applied are semantically directly affected.
– In practice, stereotypes mainly specify possible usage contexts of a class, a relationship, or a package.
44
Stereotypes in UML (1)
2003 SJSU – CmpE M.E. Fayad L14-S45 Objects & Classes
Description:– A stereotype is UML’s way of attaching extra
classifications to model items; it is one of the ways that UML is made extensible. The stereotype describes a model element, and is placed close to the affected element on a diagram, giving extra information about that element
– Some stereotypes are predefined in UML; they are automatically available and cannot be redefined. <<interface>>, <<type>>, and <<implementation class>> are examples. 45
Stereotypes in UML (2)
2003 SJSU – CmpE M.E. Fayad L14-S46 Objects & Classes
Description: (continued)– Stereotypes can be defied to express
whatever extra classification may be deemed useful.
– For example, if an application had persistent classes, the stereotype <<persistent>> could be defined to show which classes are persistent.
46
Stereotypes in UML (3)
2003 SJSU – CmpE M.E. Fayad L14-S47 Objects & Classes
Notation:– The stereotype is placed before or above the
element name and enclosed in French quotes (<<>>)
– Alternatively, special symbols may be used (decorative stereotypes). These can be seen in Rational Rose. Some of the elements that are represented in this manner are: <<actor>>, <<control>>, <<entity>>, and <<boundary>>. 47
Stereotypes in UML (4)
2003 SJSU – CmpE M.E. Fayad L14-S48 Objects & Classes
Examples:– Stereotypes can, for example, be used to
indicate the meaning of a class in the application architecture, such as:
• <<presentation>>, <<process>>, <<domain class>>.
– Further examples:• <<model>>, <<view>>, <<controller>>,
<<exception>>, <<primitive>>, <<enumeration>>, <<signal>>, <<complete>>, <<incomplete>>, <<implements>>, <<uses>>, <<extends>>
48
Stereotypes in UML (4)
2003 SJSU – CmpE M.E. Fayad L14-S49 Objects & Classes
Definition:– Interfaces describe a selected part of the
externally visible behavior of model elements (mostly of classes and components).
– Interface classes are abstract classes which define abstract operations, exclusively.
49
Interfaces & Interface Classes in UML (1)
2003 SJSU – CmpE M.E. Fayad L14-S50 Objects & Classes
Description:– Interfaces are specifications of the external behavior of
classes and contain a set of signatures for operations that classes wishing to provide this interface need to implement.
– Operations in an interface need not be explicitly marked as {abstract}, because this is mandatory.
– Common classes that wish to implement an interface need to provide all the operations defined in the corresponding interface class.
50
Interfaces & Interface Classes in UML (2)
2003 SJSU – CmpE M.E. Fayad L14-S51 Objects & Classes
Notation:– Interface classes are noted in the same way as
common classes, except that they bear the stereotype <<interface>>.
– They do not need a compartment for attributes, as they contain only operations.
– Operations in interface classes define only signatures; they are abstract and should therefore be set in italics. 51
Interfaces & Interface Classes in UML (3)
2003 SJSU – CmpE M.E. Fayad L14-S52 Objects & Classes
52
Interfaces & Interface Classes in UML (4)
Example:
String
isEqual(String):BooleanisGreater(String):Boolean
Length():Integer
<<interface>>Sortable
isEqual(Object):BooleanisGreater(Object):Boolean
Realization Relationship
2003 SJSU – CmpE M.E. Fayad L14-S53 Objects & Classes
Related terms: restriction, integrity rule, condition, tagged value, stereotype, not dependency, invariant, assertion.
Definition:– A constraint is an expression which restricts the
possible contents, states or the semantics of a model element and which must always be satisfied.
53
Constraints in UML (1)
2003 SJSU – CmpE M.E. Fayad L14-S54 Objects & Classes
Description:– A constraint describes a condition or integrity
rule.
Notation:– Constraints are enclosed in braces:
• { Constraint }
54
Constraints in UML (2)
2003 SJSU – CmpE M.E. Fayad L14-S55 Objects & Classes
Dependency
55
Constraints’ Examples in UML (3)
Project Employee{subset} 11..*
has
consists of
projectLeader
projectMembers
Project Employee11..*
has
consists of
projectLeader
projectMembers
Project self.projectMembers -> includes (self.projectLeader)
2003 SJSU – CmpE M.E. Fayad L14-S56 Objects & Classes
Consistency
56
Constraints’ Examples in UML (4)
Customer
Contract
1
0..*
has
receives
based on
Invoice self.contract.customer = self.customer
Invoice
1
1
0..*
2003 SJSU – CmpE M.E. Fayad L14-S57 Objects & Classes
OR
57
Constraints’ Examples in UML (5)
Person
Domesticaddress
{or}
*
*
has
Foreignaddress
has
2003 SJSU – CmpE M.E. Fayad L14-S58 Objects & Classes
Values
58
Constraints’ Examples in UML (6)
Rectangle
a {a > 0}b {b > 0}
Triangle
a {c-b < a < b+c}b {a-c < b < a+c}c {a-b < c < a+b}
2003 SJSU – CmpE M.E. Fayad L14-S59 Objects & Classes
Order
59
Constraints’ Examples in UML (7)
NameList1..*contains
{ordered: lastName}
1 Person
lastNamefirstName
2003 SJSU – CmpE M.E. Fayad L14-S60 Objects & Classes
Formulas
60
Constraints’ Examples in UML (8)
Person
birthDate : Date/age {age = today - birthDate}
{/age = today - birthDate}
Person
birthDate : Date/age
2003 SJSU – CmpE M.E. Fayad L14-S61 Objects & Classes
Enumerations
61
Constraints’ Examples in UML (9)
ShoppingSpree1..*
paricipants
{participant.age > 65}1 Person
age
2003 SJSU – CmpE M.E. Fayad L14-S62 Objects & Classes
Related terms: property string, feature, characteristic, constraint.
Definition:– Tagged values are user-defined, language and
tool specific keyword/value pairs which extend the semantics of individual model elements with specific characteristic properties.
62
Tagged Values in UML (1)
2003 SJSU – CmpE M.E. Fayad L14-S63 Objects & Classes
Description:– Tagged values add specific additional properties
to existing model elements. They detail the semantics of a model element and can influence code generation.
Notation:– Tagged values consist of a keyword and a
value, and are enclosed in braces.
63
Tagged Values in UML (2)
2003 SJSU – CmpE M.E. Fayad L14-S64 Objects & Classes
64
Tagged Values in UML (3)
Examples:– {abstract}– {readonly}– {private}– {obsolete}– {version=2.1}
GeomFigure{abstract Version=1.3}
visible : Boolean {readonly}
display() {abstract}remove() {abstract}getPosition(): PointsetPosition(p: Point)
setPos(x,y) {obsolete}
2003 SJSU – CmpE M.E. Fayad L14-S65 Objects & Classes
Related terms: category, subsystem Definition:
– Packages are collections of model elements of arbitrary types which are used to structure the entire model into smaller clearly visible units.
– A package defines a namespace, that is , the names of the elements within a package must be unique.
– Each model element can be referenced in other packages, but it belongs to exactly a single (home) package.
– The package can in turn contain packages. The top package includes the entire system.
65
Packages in UML (1)
2003 SJSU – CmpE M.E. Fayad L14-S66 Objects & Classes
Description:– Packages my contain different model elements,
for example, classes and use cases. They may be hierarchically structured, with packages inside packages.
– Packages are built on the basis of logical or physical relationships.
66
Packages in UML (2)
2003 SJSU – CmpE M.E. Fayad L14-S67 Objects & Classes
Description:– A model element can be contained in several
packages, but each element has its home package. In all other packages, it can only be quoted in the form:
• PackageName::ClassName
– This creates dependencies between the packages: one package uses classes of another package. 67
Packages in UML (3)
2003 SJSU – CmpE M.E. Fayad L14-S68 Objects & Classes
Description:– A good architecture leads to few
dependencies between packages. – Packages are also suitable working entities
for project management and organization.
68
Packages in UML (4)
2003 SJSU – CmpE M.E. Fayad L14-S69 Objects & Classes
Notation – A package is represented as a folder. Inside this symbol,
the name of the package is noted. – The dependencies between packages are noted by a
dashed arrow which points toward the independent package.
– It is also possible to represent generalization relations between packages if the model elements contained in the packages are generalizations or specializations of elements contained in other packages.
69
Packages in UML (5)
2003 SJSU – CmpE M.E. Fayad L14-S70 Objects & Classes
70
Packages in UML (6)
ExampleProductProduct
Online Tariffing
Online Tariffing
Tariffing Life
Tariffing Life
LifeLife
Contents&PL
Contents&PL
PartnerPartnerTariffing Contents
Tariffing Contents
2003 SJSU – CmpE M.E. Fayad L14-S71 Objects & Classes
71
Notes in UML (1)
Related Terms: annotation, comment
Definition: Notes are comments to a diagram or an arbitrary element in a diagram, without any semantic effect.
Description: notes are annotations to classes, attributes, operations, relationships, and the like.
Some analysis and design tools provide the possibility of creating notes with user-defined structures and names
2003 SJSU – CmpE M.E. Fayad L14-S72 Objects & Classes
72
Notes in UML (2)
Note Notation & Example:
Invoice
invPositions : Set
sumPositions()sumVAT()
InvPosition
quantityitem
unitPrice
totalPrice()
*1
sumPositions “This example is in Smalltalk” “Return total amount of all invoice positions” | s | s:= 0. invPositions do: [:p | s:= s + ( p totalAmount).]. ^s.
2003 SJSU – CmpE M.E. Fayad L14-S73 Objects & Classes
Related items: mechanism
Description: Class models and the like are substantially easier to understand when one knows where design patterns have been employed.
Therefore, it is sensible to document this in the model in an appropriate manner. 73
Cooperation / Design Pattern Notation in UML (1)
2003 SJSU – CmpE M.E. Fayad L14-S74 Objects & Classes
74
Cooperation / Design Pattern Notation in UML (2)
Productelement
ProductProduct
price
Contract11..*
composite
Composite(Gamma et al. 1995)
sheet
componentclient
2003 SJSU – CmpE M.E. Fayad L14-S75 Objects & Classes
• T/F statements
1. Abstract classes are used to generate object instances
2. Legacy Software is any preexisting software that must be replaced by, incorporated into, or interfaced with software that is currently being developed
3. Utility class contains global variables and functions.
4. Design patterns identify, name, and describe common and recurring designs appearing frequently in object-oriented systems.
• Define in UML: Abstract Classes, Objects, Metaclasses, Parameterized Classes, Utility Classes, and Notes
75
Discussion Questions
2003 SJSU – CmpE M.E. Fayad L14-S76 Objects & Classes
76
Questions for the Next Lecture
Define:–RRelationships–AAssociation relationships
Aggregation
Inheritance
–A