1 Software Engineering Dr. K. T. Tsang Lecture 5 Class modeling kentsang/SWE/SWE.htm.
-
Upload
branden-lamb -
Category
Documents
-
view
215 -
download
2
Transcript of 1 Software Engineering Dr. K. T. Tsang Lecture 5 Class modeling kentsang/SWE/SWE.htm.
1
Software EngineeringDr. K. T. Tsang
Lecture 5
Class modelinghttp://www.uic.edu.hk/~kentsang/SWE/SWE.htm
Class & objects: focus of class modeling
Person
Class
Objects
JoeSmith:Person
MarySmith:Person
:Person
Anonymous object
Attributes & values
Person
name: stringbirthday: datephoneNumber: string
JoeSmith:Person
name=“JoeSmith”birthday=21 October 1988phoneNumber=555666
name=“MarySmith”birthday=12 May 1977phoneNumber=222333
MarySmith:Person
Attribute nametype
value
Operations and methods
• An operation is a function/procedure that may be applied to or by objects in the class.
• A method is the implementation of an operation for a class.
• When an operation has methods on several classes, it is important that the methods all have the same signature – the number & types of arguments & the type of return value.
Person
name: stringbirthday: datephoneNumber: string
method name
Operations and methods (2)
changeJobchangeAddress
File
fileNamesizeInByteslastUpdate
colorposition
GeometricObject
move(delta: Vector)select(p: Point): Booleanrotate(in angle: float=0.0)
directiontype
Default value
Argument name
Return type
Direction of arguments
• The direction of an argument indicates whether it is an input (in), output (out), or an input that can be modified (inout).
Link & Association
• A link is a physical or conceptual connection among objects.
• An association is – a description of a group of links with common
structure and common semantics.– a set of potential links in the same way that a
class describes a set of potential objects.
Multiplicityis the number of instances of one class that may
relate to a single instance of an associated class.
• UML diagrams explicitly list multiplicity at the ends of the association lines:– “1” exactly one– “1..*” one or more– “3..5” three to five, inclusive– “*” many (zero or more)
• Cardinality is the actual number of instances that is related to a single instance of an associated class.
• Multiplicity is a constraint on the cardinality.
Link & Association: example
Person
name: stringbirthday: datephoneNumber: string
Company
name
OwnsStock* *many to many
Joe:Person
name=“Joe”
Mary:Person
name=“Mary”
Amy:Person
name=“Amy”
Microsoft:Company
name=“Microsoft”
IBM:Company
name=“IBM”
Association End Names: example
Joe:Person
name=“Joe”
Mary:Person
name=“Mary”
Amy:Person
name=“Amy”
Microsoft:Company
name=“Microsoft”
IBM:Company
name=“IBM”
Person
name: stringbirthday: datephoneNumber: string
Company
name
WorksFor* 0..1employee employer
Association End Names: example
Person
name: stringbirthday: datephoneNumber: string
parent
child *
0..2
Ordering of association
Screen Window1 *
{ordered}
VisibleOn
Bags & Sequences• Bag – a collection of elements with duplicates
allowed.
• Sequence – an ordered collection of elements with duplicates allowed.
Itinerary Airport* *
{sequence}
Association classes
• It is an association that is also a class
• It has attributes.
File User
* *AccessibleBy
accessPermission
/etc/temp read John
/etc/temp read-write Mary
/usr/bin read-write John
Association classes - example
Person
name: stringbirthday: datephoneNumber: string
Company
name
* 0..1employee employer
Workfor
salaryjobTitle
Manages
PerformanceRating
*
0..1
worker
boss
Association class or ordinary class
Person
name: stringbirthday: datephoneNumber: string
Company
name
* *
OwnStock
quantity
Person
name: stringbirthday: datephoneNumber: string
Company
name* *Purchase
quantitydatacost
1 1
Qualified association
Bank Account
accountNumberBank Account 1 0..1
1 *
Qualified association
StockExchange
Company
tickerSymbol
StockExchange
Company
Lists
tickerSymbol
*
*
*0..1
Lists
qualifiedunqualified
Generalization & Inheritance
• Generalization – the relationship between a class (superclass) and its specialization (subclasses)
• Also called “is-a” (is-kind-of) relationship
• 3 purposes– Organize a hierarchy– Enable code reuse– Support polymorphism – overriding features of
the superclass
Fig.3.25 in p.39 B & R
Inheritance for graphic figures
Fig.3.28 in p.46 B & R
Fig.3.27 in p.44 B & R
Object constraint language - OCL
• Attributes – source_object + “.” + attribute_name
• Operations - source_object + “.” + operation_name + “()”
• Simple association – traverse an association : aCreditCardAccount.MailingAddress
• Qualified association – more precise traversal : aCreditCardAccount.Statement[10 Aug 2007]
• Filters – most commonly used : “select”– aStatement.Transaction->select(amount>$100)
Class Responsibility Collaborator cards
• CRC cards, being proposed by Ward Cunningham and Kent Beck, are a brainstorming tool used in the design of object-oriented software.
• They are typically used when first determining which classes are needed and how they will interact.
• http://anonymouse.org/cgi-bin/anon-www.cgi/http://en.wikipedia.org/wiki/Crc_cards
CRC cards..1
CRC cards are usually created from index cards on which are written:
• The class name
• Its Super and Sub classes (if applicable)
• The responsibilities of the class.
• The names of other classes with which the class will collaborate to fulfill its responsibilities.
• Author
• Using a small card keeps the complexity of the design at a minimum. It focuses the designer on the essentials of the class and prevents him from getting into its details and inner workings at a time when such detail is probably counter-productive.
CRC cards..2
Reading for this lecture
• Chapter 3 Blaha & Rumbaugh
• Study the class models in examples– http://www.cs.gordon.edu/courses/cs211/
AddressBookExample/index.html– http://www.cs.gordon.edu/courses/cs211/
ATMExample/index.html