Software Engineering I Oct. 9, 2013 Notes Unified Modeling Language (UML) by Object Management Group (OMG) -Developed in the mid 1990's by James Rumbaugh, Grady Booch, and Ivar Jacobson UML Includes - Class diagrams - describe Java/C++/other classes - Interaction diagrams - show sequence and communication in programs - State and Activity Diagrams - show system behavior + How functionality works - Component and Deployment Diagrams + Show entire system design Why use UML? UML is easy to understand Lots of people use it It is standardized Other programmers will know what you mean if you follow the standard Helps with modeling Includes detailed semantics Extendable to other concepts that are not part of UML Also includes a text based language called the Object Constraint Language or OCL UML is a standard not a methodology standard - common way of doing something Ex: Standards exist for Java, C, C++, Python, Ethernet connections TCP/IP, etc. Just because you know the standard doesn't mean you know how to use it methodology - step by step process Let's look at UML class diagrams first These include: -classes - represent data types -associations - show how classes reference other classes -attributes - data within classes -operations - functions performed by instances of classes -generalizations (parent/child relationships) - show inheritance hierarchies Multiple levels of detail are possible with UML Assume a rectangle class public class Rectangle { private int height; private int width; public int getArea() { return width * height; } public void resize(int h, int w) { height = h; width = w; } } Convert this to UML +-----------------------+ | Rectangle | +-----------------------+ | -height: int | <-- the minus sign indicates private | -width: int | +-----------------------+ | +getArea(): int | <-- the plus sign indicates public | +resize(): int | +-----------------------+ We could leave out some of the detail like types and protection levels. Multiplicities (Association) - "has a" relationship * - indicates many other values indicate multiplicity - how many objects Many (0 or more) to one +------------+ * works for 1 +---------+ | Employee |---------------------| Company | +------------+ +---------+ Many to many +---------------+ * works for 1..* +---------+ | AdminAssistant|------------------------| Manager | +---------------+ Supervisor +---------+ One to one +---------+ 1 1 +------------------+ | Company |---------------------| BoardOfDirectors | +---------+ +------------------+ Other relationships +---------+ 0..1 * +----------+ | Office |---------------------| Employee | +---------+ allocatedTo |> +----------+ +---------+ 0, 3..8 * +------------------+ | Person |---------------------| BoardOfDirectors | +---------+ Board +------------------+ Member Associations may be named Role names may be attached to either or both ends of the association Reflexive associations These connect a class to itself +---------+ *| | +------------+ | isMutuallyExclusive successor * | |------+ +---------| Course | * | +------------+ | * | +------------+ prerequisite Roles may be either symmetric - that is, the same on both ends like "isMutuallyExclusive" or asymmetric - different on both ends like "successor" and "prerequisite" where the roles of classes on each end are different Associations can have directionality that limits navigability +--------+ * <| PlayedInYear 1 +----------+ | Year |<-------------------------| Player | +--------+ year +----------+ This means that class player has 0 or more years in which he/she played The line with the arrow indicates that the Year class has no reference to the Player class. Rather, the player class has a reference to the year class Ex: public class Player { //instance variables go here ArrayList year; ... } public class Year { int year; ... }