Software Engineering UML Class Diagrams 1 UML Example

  • Slides: 22
Download presentation
Software Engineering UML Class Diagrams 1

Software Engineering UML Class Diagrams 1

UML Example of a Class • attributes (fields, instance variables) • visibility name :

UML Example of a Class • attributes (fields, instance variables) • visibility name : type [count] = default_value • visibility: + # ~ public protected private package (default) • underline static attributes • derived attribute: not stored, but can be computed from other attribute values • attribute example: - balance : double = 0. 00 2

Class operations / methods • visibility name (parameters) : return_type • visibility: + public

Class operations / methods • visibility name (parameters) : return_type • visibility: + public # protected private ~ package (default) • underline static methods • parameter types listed as (name: type) • omit return_type on constructors and when return type is void • method example: + distance(p 1: Point, p 2: Point): double 3

Comments • represented as a folded note, attached to the appropriate class/method/etc by a

Comments • represented as a folded note, attached to the appropriate class/method/etc by a dashed line 4

Relationships between classes: • generalization: an inheritance relationship • inheritance between classes • interface

Relationships between classes: • generalization: an inheritance relationship • inheritance between classes • interface implementation • association: a usage relationship • dependency • aggregation • composition 5

Generalization relationships • generalization (inheritance) relationships • hierarchies drawn top-down with arrows pointing upward

Generalization relationships • generalization (inheritance) relationships • hierarchies drawn top-down with arrows pointing upward to parent • line/arrow styles differ, based on whether parent is a(n): • class: solid line, black arrow • abstract class: solid line, white arrow • interface: dashed line, white arrow • we often don't draw trivial / obvious generalization relationships, such as drawing the Object class as a parent 6

Associational relationships • associational (usage) relationships 1. multiplicity (how many are used) • •

Associational relationships • associational (usage) relationships 1. multiplicity (how many are used) • • * 1 2. . 4 3. . * 0, 1, or more 1 exactly between 2 and 4, inclusive 3 or more 2. name (what relationship the objects have) 3. navigability (direction) 7

Class diagram example 1 Textbook Rental System visibility Customer -CID: int -name: String +authenticate.

Class diagram example 1 Textbook Rental System visibility Customer -CID: int -name: String +authenticate. Customer () attributes multiplicity 1. . * rents 1. . * class name Textbook -book. ID : int -book. Volume. No: int +rent. Book() relationship methods

Class diagram example 2 Multiplicity Customer Class Simple 1 Aggregation Rental Invoice Abstract Class

Class diagram example 2 Multiplicity Customer Class Simple 1 Aggregation Rental Invoice Abstract Class Rental Vehicle 1. . * 1 0. . 1 Composition Simple Generalization Car 9 Association SUV Moving. Van Checkout Screen

Class diagram example 3 Student. Body + main (args : String[]) 1 100 Student

Class diagram example 3 Student. Body + main (args : String[]) 1 100 Student - first. Name : String last. Name : String home. Address : Address school. Address : Address + to. String() : String Address - street. Address : String city : String state : String zip. Code : long + to. String() : String

Tools for creating UML diags. • Lucidchart • http: //www. lucidchart. com/ • Rational

Tools for creating UML diags. • Lucidchart • http: //www. lucidchart. com/ • Rational Rose • http: //www. rational. com/ • Visual Paradigm UML Suite (trial) • http: //www. visual-paradigm. com/ • (nearly) direct download link: http: //www. visual-paradigm. com/vp/download. jsp? product=vpuml&edition=ce (there are many others, but most are commercial) 11

Topics • Process 12

Topics • Process 12

Review

Review

OOP Analysis Process • Four-step Process

OOP Analysis Process • Four-step Process

Step 1 The first step is to obtain or prepare a textual description of

Step 1 The first step is to obtain or prepare a textual description of the problem to be solved.

Step 2 Examine the description and underline nouns. The nouns will become classes in

Step 2 Examine the description and underline nouns. The nouns will become classes in the analysis.

Step 3 Examine the description and underline adjectives in the document. These adjectives will

Step 3 Examine the description and underline adjectives in the document. These adjectives will describe the attributes of the classes that we previously identified.

Step 4 • Analyze the active verbs in the description. • The active verbs

Step 4 • Analyze the active verbs in the description. • The active verbs will give us the operations (methods) that we'll need to define for our classes.

Problem You have been tasked with creating an online shopping website. Users can add

Problem You have been tasked with creating an online shopping website. Users can add more than one item on sale at a time to a shopping cart. What elements should be modeled as classes? • Item • Rating • Price • Shopping. Cart • Time • User

Practice

Practice

Course Management System 1. The Registration Manager sets up the curriculum for a semester

Course Management System 1. The Registration Manager sets up the curriculum for a semester using a scheduling algorithm. 2. One course may have multiple course offerings 3. Each course offering has a number, location, and time. 4. Students select 4 primary courses and 2 alternative courses by submitting a registration form. 5. Students may use the system to add/drop courses for a period of time after registration. 6. Professors use the system to receive their course offering rosters. 7. Users of the registration system are assigned passwords, which are used at login validation. Build the Class Diagram