Unified Modeling Language UML UML q Graphic modeling

  • Slides: 26
Download presentation
Unified Modeling Language (UML)

Unified Modeling Language (UML)

UML q Graphic modeling language for describing object-oriented software. q Started in 1994 q

UML q Graphic modeling language for describing object-oriented software. q Started in 1994 q Combined notations from 3 leading OO methods § OMT, Object-modeling technique (James Rumbaugh) § OOSE, Object-oriented software engineering (Ivar Jacobson) § Booch method (Grady Booch)

Core UML Diagrams A diagram is the graphical presentation of a set of elements,

Core UML Diagrams A diagram is the graphical presentation of a set of elements, most often rendered as a connected graph of things and relationships. q Use case diagrams § Describe functional behavior seen by (external) users q Class diagrams § Describe static structure of the classes in system

Use case diagrams Use Case Diagrams describe the functionality of a system and users

Use case diagrams Use Case Diagrams describe the functionality of a system and users of the system, i. e. what a new system should do or what an existing system already does. These diagrams contain the following elements: q Actors, which represent users of a system, including human users and other systems. q Use Cases, which represent functionality or services provided by a system to users. System boundary Association System Use Case Actor (People) Use Case Actor (Systems)

An use-cases example Library Borrow books Return books Interlibrary loan Circulation Clerk Do research

An use-cases example Library Borrow books Return books Interlibrary loan Circulation Clerk Do research Member Read books, newspaper Purchase supplies Supplier

Class diagrams The class diagram is the main building block in object oriented modeling.

Class diagrams The class diagram is the main building block in object oriented modeling. It q represents the static structure of a system, q describes how a system is structured rather than how a system behaves. q contains the following elements: § Classes, which represent entities with common characteristics or features. These features include attributes and operations. § Associations, which represent relationships between classes.

Basic UML notation for classes Class name attribute: primitive. Data. Type or Class attribute:

Basic UML notation for classes Class name attribute: primitive. Data. Type or Class attribute: type or Class=default value Attribute visibility - (private) # (protected) + (public) ~(package) Operations - (private) # (protected) + (public) method (argument_list): type or Class Basic UML notation for classes

Example Basic UML notation for classes Class name Transcript +student. Name: String +student. ID:

Example Basic UML notation for classes Class name Transcript +student. Name: String +student. ID: int +list. Of. Course. Names: List=null +lilst. Of. Grades: List=null +GPA: int Operations +set. Student. Name(String name) +set. Student. ID(int ID) +add. Course. Name(String course) +add. Grade(Char grade) +calculate. Average(): int +show() Attribute

Parameterized classes Stack +pop() : <type> type

Parameterized classes Stack +pop() : <type> type

Basic Class Relationships Class A Class with parts Class A Superclass Interface Assembly Class

Basic Class Relationships Class A Class with parts Class A Superclass Interface Assembly Class B Subclass Concrete Class name Class B Association Aggregation Composition Dependency Inheritance Realization (Generalization)

Associations • A link between two classes – Typically modeled as a member reference

Associations • A link between two classes – Typically modeled as a member reference • A Person works for a Company multiplicity Role names employee Person 0. . * employer works for 1 Company Association Name • Role names and multiplicity at association ends • Direction arrow to aid reading of association name

Recursive Association Person Node Connects married to

Recursive Association Person Node Connects married to

Aggregation q A special form of association that models a whole-part relationship between an

Aggregation q A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts. § Models a “is a part-part of” relationship. multiplicity 4 Wheel wheels Car Whole Part

Composition q A strong form of aggregation § The whole is the sole owner

Composition q A strong form of aggregation § The whole is the sole owner of its part • The part object may belong to only one whole § Multiplicity on the whole side must be one § The life time of the part is dependent upon the whole • The composite must manage the creation and destruction of its parts multiplicity Line Polygon 2 Point 3. . *

Dependency q A dependency indicates a semantic relation between two or more classes in

Dependency q A dependency indicates a semantic relation between two or more classes in which a change in one may force changes in the other although there is no explicit association between them q A stereotype may be used to denote the type of the dependency Vector Iterator

Generalization q Indicates that objects of the specialized class (subclass) are substitutable for objects

Generalization q Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) § “is a” relationship Shape Super Class Circle Sub Class Generalization relationship May be an abstract class

Generalization conti. q A sub-class inherits from its super-class § Attributes § Operations §

Generalization conti. q A sub-class inherits from its super-class § Attributes § Operations § Relationships q A sub-class may § Add attributes and operations § Add relationships § Refine (override) inherited operations

Realization q A realization relationship indicates that one class implements a behavior specified by

Realization q A realization relationship indicates that one class implements a behavior specified by another class (an interface or abstract class). q An interface can be realized by many classes. q A class may realize many interfaces. Linked. List <<interface>> List Linked. List

Basic Class Diagram (Example) Head Arm Person Class Student takes

Basic Class Diagram (Example) Head Arm Person Class Student takes

Example: Class Diagram Student Transcript * Course Student student. Name student. ID list. Of.

Example: Class Diagram Student Transcript * Course Student student. Name student. ID list. Of. Courses. ID transcript: Transcript set. Student. Name() get. Student. Name() set. Student. ID() get. Student. ID() add. To. Listof. Course. IDs() make. Transcript() Transcript student. Name student. ID list. Of. Course. Names lilst. Of. Grades average set. Student. Name() set. Student. ID() add. Course. Name() add. Grade() calculate. Average() show() Course course. Name course. ID grade read. Course. Data() read. Course. Grade() set. Course. ID()

UML Class Diagrams Java Code q Different representations of the same information § Name,

UML Class Diagrams Java Code q Different representations of the same information § Name, state, behavior of class § Relationship(s) between classes § Should be able to derive one from the other q Motivation § UML Java • Implement code based on design written in UML § Java UML • Create UML to document design of existing code

Java UML: Clock Example Java class Clock // name { // fields, members int

Java UML: Clock Example Java class Clock // name { // fields, members int seconds; int minutes; int hours; // methods void start(); void adjust. Time(); void reset(); } Java code Name Attributes Operations Class diagram

Two basic relationships of Java classes class A { …. } class B extends/implements

Two basic relationships of Java classes class A { …. } class B extends/implements A { … } Class B is-a class A { …. } class B { A x = new A(); … } Class B has-a class A. q Relationships association, aggregation and dependency are has-a relationships. q Generalization and realization are is-a relationships.

UML Packages q A package is a general purpose grouping mechanism. § Can be

UML Packages q A package is a general purpose grouping mechanism. § Can be used to group any UML element (e. g. use case, actors, classes, components and other packages. q Commonly used for specifying the logical distribution of classes. Name

Packages and Class Diagrams • Add package information to class diagrams b a b.

Packages and Class Diagrams • Add package information to class diagrams b a b. a. F a. A b. b. E b. b. D a. B b. a. G a. C

Homework A B C D E F In the following questions fill in is-a

Homework A B C D E F In the following questions fill in is-a or has-a. 1. Class D ______ class A. 2. Class D ______ class E. 3. Class E ______ class B. 4. Class E ______ class C. 5. Class F ______ class E.