A means of graphically displaying a complicated programs 18-Mar-16 UML Thanks to Dave Matuczek, UPenn
What is UML? 2 UML stands for Unified Modeling Language or Universal Modeling Language UML uses graphics to show the relationships between program classes and objects.
Design Patterns 3 Design Patterns common programming strategies Design Patterns are best described by UML We will learn some simple patterns in class
Classes 4 A class is drawn as a rectangle with three sections Name of the class Variables Methods
Variables 5 A variable is written as: domain name : type where: + means public - means private Example: +length:int
Variables 6 Static variables are underlined An initial value can be shown with =value Example: -numberOfEmployees:int=10 means numberOfEmployees is: private static integer and has 10 as its initial value
Methods 7 Methods are written as: domain name (parameters) : returnType where Domain uses the same syntax variables (+, -, blank) parameters are given as name:type if the returnType is void, it is omitted constructors are preceded by «constructor» interfaces are preceded by «interface»
Example of a class 8 Card +cardId:int -copy:boolean=false «constructor» Card( int id ) +isKind( desiredKind:int ) +isSharable( ):boolean +toString( ):String
Types of relationships 9 A B class B extends class A C D 1..4 “Is a”“Has a” Class C contains 1 to 4 objects of class D IGeometry Cube Implements
Example: Geometry program 10
Dependency "uses " No instantiation OBJECT new BankClass( );
Composition "has a" object instantiation public BankAccountClass myAccount; myAccount = new BankAccountClass( ….
Inheritance “is a” public class Clock extends JFrame
Realization interface implementation public class BankAccountClass implements IBankAccountClass
Association "knows a" object is passed public BankAccountClass( double money, int acct, PeopleClass person ) { balance = money; accountNumber = acct; member = person; }