Unified Modeling Language (UML)
UML Graphic modeling language for describing object-oriented software. Started in 1994 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, most often rendered as a connected graph of things and relationships. Use case diagrams Describe functional behavior seen by (external) users Class diagrams Describe static structure of the classes in system
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: Actors, which represent users of a system, including human users and other systems. Use Cases, which represent functionality or services provided by a system to users. System boundary Association Actor (People) Actor (Systems) Use Case System
An use-cases example Library Supplier Borrow books Return books Interlibrary loan Circulation Clerk Do research Read books, newspaper Member Purchase supplies Supplier
Class diagrams The class diagram is the main building block in object oriented modeling. It represents the static structure of a system, describes how a system is structured rather than how a system behaves. 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 Class name attribute:primitiveDataType or Class attribute: type or Class=default value method ( ) method (argument_list):type or Class Attribute visibility - (private) # (protected) + (public) ~(package) Operations - (private) # (protected) + (public) Basic UML notation for classes
Basic UML notation for classes Example Basic UML notation for classes Class name Transcript +studentName: String +studentID: int +listOfCourseNames: List=null +lilstOfGrades:List=null +GPA: int +setStudentName(String name) +setStudentID(int ID) +addCourseName(String course) +addGrade(Char grade) +calculateAverage(): int +show() Attribute Operations
Parameterized classes type Stack +pop() : <type>
Basic Class Relationships Class A Class with parts Class with parts Class A Superclass Interface name Class B Assembly Class Assembly Class Class B Subclass Concrete Class Association Aggregation Composition Inheritance (Generalization) Dependency Realization
Associations A link between two classes Typically modeled as a member reference A Person works for a Company multiplicity Role names employee employer Person Company 0..* 1 works for Association Name Role names and multiplicity at association ends Direction arrow to aid reading of association name
Recursive Association Person Node Connects married to
Aggregation 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 Car Wheel wheels Whole Part
Composition 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 Point 3..* 2 Polygon
Dependency 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 A stereotype may be used to denote the type of the dependency Iterator Vector
Generalization Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class) “is a” relationship Shape Super Class May be an abstract class Generalization relationship Sub Class Circle
Generalization conti. A sub-class inherits from its super-class Attributes Operations Relationships A sub-class may Add attributes and operations Add relationships Refine (override) inherited operations
<<interface>> List Realization A realization relationship indicates that one class implements a behavior specified by another class (an interface or abstract class). An interface can be realized by many classes. A class may realize many interfaces. LinkedList <<interface>> List LinkedList List
Basic Class Diagram (Example) Person Head Arm Class Student takes
Example: Class Diagram Student Transcript Course * Transcript studentName studentID listOfCourseNames lilstOfGrades average setStudentName() setStudentID() addCourseName() addGrade() calculateAverage() show() Student studentName studentID listOfCoursesID transcript:Transcript setStudentName() getStudentName() setStudentID() getStudentID() addToListofCourseIDs() makeTranscript() Course courseName courseID grade readCourseData() readCourseGrade() setCourseID()
UML Class Diagrams Java Code Different representations of the same information Name, state, behavior of class Relationship(s) between classes Should be able to derive one from the other 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 seconds; int minutes; int hours; // methods void start(); void adjustTime(); void reset(); } Name Attributes Operations Class diagram Java code
Two basic relationships of Java classes class A { …. } class B { A x = new A(); … } Class B has-a class A. class A { …. } class B extends/implements A { … } Class B is-a class A. Relationships association, aggregation and dependency are has-a relationships. Generalization and realization are is-a relationships.
UML Packages 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. Commonly used for specifying the logical distribution of classes. Name
Packages and Class Diagrams Add package information to class diagrams b a b.a a.A b.b.D b.b.E b.a.F b.a.G a.C a.B b.b
Homework A B C D E F In the following questions fill in is-a or has-a. Class D ______ class A. Class D ______ class E. Class E ______ class B. Class E ______ class C. Class F ______ class E.