UML Class Diagram PDF

Title UML Class Diagram
Author Hailey AYDIN
Course Software Engineering
Institution William Paterson University
Pages 20
File Size 373.8 KB
File Type PDF
Total Downloads 93
Total Views 165

Summary

Use case model class diagram introduction...


Description

Object-Oriented Software Development

UML – Class Diagram

Object Orientation • Identity (name, reference, handle) – Data (states, attributes) and action/behavior (services, operations, methods, functions) are organized into discrete, indistinguishable entities • Abstraction – Forms a hierarchy that shows different system perspectives relate to one another • Classification – Group objects that have attributes and behaviors in common • Object is an instance of a class – A class describes a set of objects that share a common structure and common behaviors, but the attribute values help us distinguish particular objects from one another 2

UML Class Diagram • Class diagram = object model/template, object type • Object diagram – model objects and their connections, or links • Describe the object types (classes) and their static relationships (relationships between classes) • The major purpose of other UML diagrams is to support the construction and testing of the class diagram. In other words, class diagram is very important (obviously) for object-oriented program

3

UML Diagrams Use Case Model

Object Diagram

Interaction Diagrams

Sequence Diagram Class Diagram Communication Diagram Activity Diagram

State Diagram

4

Identify Classes/Objects • The design process starts with a statement of the requirements. We try to extract nouns, looking for particular items that can suggest at classes – A class can be a real thing or an abstract thing

• What needs to be “processed” in some way? • Class usually has multiple attributes • What attributes and operations are always applicable to a class or object? • Think about instances – Objects are instances of a class – Values are instances of an attribute 5

Identify Attributes (Variables) • Characteristics of an object • Characteristic that is common to all instances of the object/class is abstracted as an attribute • An attribute is some variable (data item, state information) for which each object has its own value • Attribute has a name that is unique within the object/class • Attribute may take on values, and value ranges (has exactly one value for each attribute at any given time; e.g., age)

6

Identify Objects/Attributes • From the requirements document, search for adjectives and possessive phrases – E.g., red car, 30-year old man, the color of the truck, etc.

• If description contains a noun, then try to model it as an object. But if the noun can take a value, then it is probably an attribute and not an object • If XYZ has a key (unique identifier), then XYZ is usually an object and the key itself is an attribute of XYZ • If you want to keep track of information about ABC, then ABC is probably an object 7

UML Class Element: Attributes Class Name Attributes

Operations Attributes: VISIBILITY NAME: TYPE = DEFAULT VALUE{CONSTRAINTS} VISIBILITY: public(+), protected(#), private(-) NAME: a string by which the attribute is identified TYPE: attribute type(e.g., non-negative integer) VALUE: initial value if assigned (optional) CONSTRAINT: (optional) NOTE: “/” before an attribute is a derived attribute (optional). Protected visibility is for generalization (inheritance hierarchy). E.g., + CompanyName : character = spaces {1 to 30 characters, spaces, hyphens, commas, periods} 8

Identify Operations/Services • A service/operation may be defined as work done for others • The services of an object are the advertised or public work that an object is willing to perform when requested by another object via the message-passing paradigm • Services are defined by prototypes – Name of the service (selector) – Arguments (parameters) for the service (signature)

• The defined collection of prototypes is the protocol of the class/object, which is the object’s interface (i.e, all of its advertised services) 9

Identify Operations • A method is a detailed set of operations that an object performs when another object requests a service • A method is how a service is implemented • A method (function) is a specific behavior of an object • Behavior/action is related to how an object acts when providing a service (actions or responsibilities taken by a class or object, or actions done to a class or object) • In finding services, we should use the verbs in our requirements document – E.g., students register for classes. Registration may be a service. 10

UML Class Element: Operations Class Name Attributes Operations Operations: VISIBILITY NAME(PARAMETER-LIST): RETURN-TYPE{CONSTRAINTS}

VISIBILITY: public(+), protected(#), private(-) NAME: a string by which the operation is identified PARAMETER-LIST: DIRECTION NAME : TYPE = DEFAULT VALUE, separated by commas (optional) DIRECTION: input(in),output(out),both(inout) NAME: parameter name TYPE: parameter type DEFAULT VALUE: initial value of the parameter, if any RETURN-TYPE: commas separated list of return types (optional) CONSTRAINT: (Optional)

11

Operation Examples EXAMPLE 1: + AverageGrade (in grades : listofgrades) : numeric {2 decimals} NOTE: types can be user defined types. EXAMPLE 2: - TotalPrice (unitprice : float, discount : percentage) : dollar

12

Class Example CUSTOMER -

name:string=blank mailingaddress:string=null accountbalance:dollar=0 customerid:integer=0 {5 digits}

+ + + + + +

getName():string setName(name:string=blank) getAccountBalance() setAccountBalance():dollar calculatebalance() getAddress() setAddress(street:string, city:string, statecode:string=NJ, zipcode:numeric=00000) + getCustID() + setCustID(integer)

13

More Notations TEXT/NOTE BOX: Class Name Attributes Operations

Text, Notes

CLASS(Name only): Customer

OBJECT(Name Only):

anObject:aClass

14

I-Bookstore Example (LOGON Use Case) • • • •

Name: LOGON Author: Mary Roe and John Doe Last Update: 9/7/2020 Pre-Conditions: – The user (customer, System Administrator, Catalog or Inventory managers) of IBookstore has already registered.

• Dialog: – User clicks on www.ibookstore365.com, the welcoming logon screen appears – display_logon_screen( ) – The logon screen requests user ID and Password. The screen include option for user who forget its password – capture_ID_PW( ), forget _PW( ) – User enters ID and password • System authenticates user – authenticate(ID, PW, OUT status):user_type, communicate_DB( ). Based on the user ID, the system communicates with its central DB (via SYSTEM INTERFACE Use Case) and recognizes the different functionalities that the user can perform (if status = “validated”): – – – –

Customer can shop, connect to the SHOP Use Case System Administrator can manage accounts, go to MANAGE ACCOUNTS Use Case Catalog Manager can manage catalog, go to MANAGE CATALOG Use Case Inventory Manager can handle processing order and shipping information, connect to the PROCESS ORDER Use Case

15

• Dialog (cont’d): • System did not authenticate user (status = “invalidated”). Allow the user enter ID and/or Password a maximum of 5 times. After 5 times, the user cannot use the ID and the system display a message asks the user to call 1800-IBS-HELP – error_handling_1( ), lock_user( )

– User selects “Forget Password” option – forget_PW( ) • Display a message asking user to check its email • Send email to user, ask user to create and confirm a new password. Tell user to use the new password to logon I-Bookstore (user information is stored in its central DB) – communicate_DB( ), send_email( ), error_handling_2( )

– User log off – logout( ) • User session terminates

• Post-Conditions: – User session terminates normally – logout( ) – User session terminates with message to call 1-800-IBS-HELP – error_handling_1( ) – Upon successful login, based on registered user ID, systems display appropriate menu screen from SHOP Use Case, MANAGE ACCUNTS Use Case, MANAGE CATALOG Use Case, or PROCESS ORDER Use Case 16

Identify Attributes • Characteristics of a class • Also known as attribute, variable, data item, data, state • Private attribute (information hiding) may need getters and setters functions (operations/services) • What variables we need in order to program the functions? • What are the characteristics common to all objects? For example, STUDENT is a class, objects are Peter, Paul, and Mary 17

Identify Attributes • What do we need to store for Peter, Paul, and Mary in your program? – First name, middle initial, last name, birthday, social security number, student number, phone number, address, class (freshman, sophomore, junior, senior, graduate), etc. – By the way, operations may be add_student(), delete_student(), print_student_report(), getters? setters? etc.

• What variables we need to display a screen? – x_coordinate, y_coordinate, color, border, pixel, brightness, sharpness

18

Class Diagrams Screen -

x_coordinate:int y_coordinate:int color:hex border:int pixel:int brightness:int sharpness:int

+ + + + + + +

display_logon_screen () capture_ID_PW() forget_PW() get/set_coordinate() get/set_color () get/set_resolution() get/set_brightness() get/set_sharpeness()

DB_Interface + status:string {validated, invalidated}

+ communicate_DB(){connect to central database} + authenticate(ID, PW, OUT status):user_type

I-Bookstore

+ lock_user() + logout() + send_email()

19

Class Diagrams Error_Handling - error_number: int - Error_count: int

+ error_handling_1() + error_handling_2()

• NOTE1: Remember that the example shown here is only for the LOGON Use Case. The classes can be used by other use cases and so there are most likely more operations in the classes from other use cases. For example, Screen class consists of other operations such as +display_shop_screen( ), +display_admin_screen( ), +display_catalog_screen( ), +display_inventory_screen( ), … • NOTE2: Try to create the necessary attributes for the classes of your project. • NOTE3: Don’t forget the getter and setter operations. 20...


Similar Free PDFs