Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Software Engineering Dr. K. T. Tsang Lecture 5 Class modeling

Similar presentations


Presentation on theme: "1 Software Engineering Dr. K. T. Tsang Lecture 5 Class modeling"— Presentation transcript:

1 1 Software Engineering Dr. K. T. Tsang Lecture 5 Class modeling http://www.uic.edu.hk/~kentsang/SWE/SWE.htm

2 Class & objects: focus of class modeling Person Class Objects JoeSmith:Person MarySmith:Person :Person Anonymous object

3 Attributes & values Person name: string birthday: date phoneNumber: string JoeSmith:Person name=“JoeSmith” birthday=21 October 1988 phoneNumber=555666 name=“MarySmith” birthday=12 May 1977 phoneNumber=222333 MarySmith:Person Attribute name type value

4 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.

5 Person name: string birthday: date phoneNumber: string method name Operations and methods (2) changeJob changeAddress File fileName sizeInBytes lastUpdate color position GeometricObject print move(delta: Vector) select(p: Point): Boolean rotate(in angle: float=0.0) direction type Default value Argument name Return type

6 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).

7 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.

8 Multiplicity is 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.

9 Link & Association: example Person name: string birthday: date phoneNumber: 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”

10 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: string birthday: date phoneNumber: string Company name WorksFor * 0..1 employee employer

11 Association End Names: example Person name: string birthday: date phoneNumber: string parent child * 0..2

12 Ordering of association ScreenWindow 1 * {ordered} VisibleOn

13 Bags & Sequences Bag – a collection of elements with duplicates allowed. Sequence – an ordered collection of elements with duplicates allowed. ItineraryAirport ** {sequence}

14 Association classes It is an association that is also a class It has attributes. File User ** AccessibleBy accessPermission /etc/tempreadJohn /etc/tempread-writeMary /usr/binread-writeJohn

15 Association classes - example Person name: string birthday: date phoneNumber: string Company name * 0..1 employee employer Workfor salary jobTitle Manages PerformanceRating * 0..1 worker boss

16 Association class or ordinary class Person name: string birthday: date phoneNumber: string Company name ** OwnStock quantity Person name: string birthday: date phoneNumber: string Company name ** Purchase quantity data cost 1 1

17 Qualified association Bank Account accountNumber Bank Account 10..1 1 *

18 Qualified association StockExchange Company tickerSymbol StockExchange Company Lists tickerSymbol * * * 0..1 Lists qualified unqualified

19 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

20 Fig.3.25 in p.39 B & R Inheritance for graphic figures

21 Fig.3.28 in p.46 B & R

22 Fig.3.27 in p.44 B & R

23 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)

24 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

25 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

26 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

27 Reading for this lecture Chapter 3 Blaha & Rumbaugh Study the class models in examples –http://www.cs.gordon.edu/courses/cs211/Addr essBookExample/index.html –http://www.cs.gordon.edu/courses/cs211/ATM Example/index.html


Download ppt "1 Software Engineering Dr. K. T. Tsang Lecture 5 Class modeling"

Similar presentations


Ads by Google