1Unified Modeling Language 2Nelson Padua-PerezChau-Wen TsengDepartment of Computer ScienceUniversity of Maryland, College ParkUML Class DiagramsRepresent the (static) structure of the systemGeneral In JavaName NameState VariablesBehavior Methods2Relationships Between ClassesAssociationPermanent, structural, “has a”Solid line with arrowheadDependencyTemporary, “uses a”Dotted line with arrowheadGeneralizationInheritance, “is a”Solid line with open triangular arrowheadImplementationDotted line with open triangular arrowheadORAssociationDenotes permanent, structural relationship Occurs when state of class A contains class BView as a “has a” relationship between classesRepresented by solid line (with arrowhead)ExampleClass Car { Class Engine {Engine myEngine; …}}Car “has a” Engine3Association w/ NavigationNavigation informationRelationship between classes may be directionalArrowhead indicates direction of relationshipCar class knows about Engine class Engine class doesn’t know about CarAssociation w/ NavigationOne-way associationOnly one class contains other classUse arrowhead to indicate direction of relationshipPoint to class contained in 2ndclassExampleClass Car { Class Engine {Engine myEngine; …}}4Association w/ NavigationBi-directional associationBoth classes contain object of other classUse undirected solid edge (no arrowheads)ExampleClass Car { Class Engine {Engine myEngine; Car myCar;}}Multiplicity of AssociationsSome relationships may be quantifiedMultiplicity denotes how many objects the source object can legitimately referenceNotation* ⇒ 0, 1, or more5 ⇒ 5 exactly5..8 ⇒ between 5 and 8, inclusive5..* ⇒ 5 or more5Multiplicity of AssociationsMany-to-oneBank has many ATMs, ATM knows only 1 bankOne-to-manyInventory has many items, items know 1 inventoryDependencyDenotes dependence between classesAlways directed (Class A depends on B)Represented by dotted line with arrowheadA depends on B AB6DependencyCaused by class methodsMethod in Class A temporarily “uses a” object of type Class BChange in Class B may affect class AA uses object of class B ABDependencyDependence may be caused byLocal variableParameterReturn valueExampleClass A { Class B {B Foo(B x) { …B y = new(); …return y; …}} }7Dependency ExampleClass Driver depends on Class Car GeneralizationDenotes inheritance between classesCan view as “is-a” relationshipRepresented by line ending in (open) triangleLaptop, Desktop, PDA inherit state & behavior from Computers8ImplementationDenotes class implements Java interface Represented by dotted line ending in (open) triangleA implements interface B A «B»UML ExamplesRead UML class diagramTry to understand relationshipsExamplesPets & ownersComputer disk organizationLibrary booksBanking systemHome heating systemPrinting system9UML Example – Veterinary SystemTry to read & understand UML diagramUML Example – Veterinary SystemTry to read & understand UML diagram• 1 or more Pets associated with 1 PetOwner10UML Example – Computer SystemTry to read & understand UML diagramUML Example – Computer SystemTry to read & understand UML diagram• 1 CPU associated with 0 or more Controllers• 1-4 DiskDrives associated with 1 SCSIController• SCSIController is a (specialized) Controller11UML Example – Library SystemTry to read & understand UML diagramUML Example – Library SystemTry to read & understand UML diagram• 1 or more Book associated with 1 or more Pages• Patron & Shelf temporarily use (depend on) Books12UML Example – Banking SystemTry to read & understand UML diagramUML Example – Banking System• 1 Bank associated with 0 or more Accounts• Checking, Savings, MoneyMarket are Accounts13UML Example – Home Heating SystemTry to read & understand UML diagramUML Example – Home Heating System• Each Thermostat has 1 Room • Each Thermostat associated with 0 or more Heaters• ElectricHeater is a specialized Heater• AubeTH101D is a specialized Thermostat14UML Class Diagrams ↔ JavaDifferent representation of same informationName, state, behavior of classRelationship(s) between classesPractice deriving one from the otherAccurately depicting relationship between classesUML → Java : Veterinary SystemUMLJava15UML → Java : Veterinary SystemUMLJavaclass Pet {PetOwner myOwner; // 1 owner for each pet}class PetOwner {Pet [ ] myPets; // multiple pets for each owner}Java → UML : Veterinary SystemJavaclass Pet {PetOwner myOwner; // 1 owner for each pet}class PetOwner {Pet [ ] myPets; // multiple pets for each owner}UML16Java → UML : Veterinary SystemJavaclass Pet {PetOwner myOwner; // 1 owner for each pet}class PetOwner {Pet [ ] myPets; // multiple pets for each owner}UMLUML Class Diagrams ↔ JavaUMLJavaclass Pet {PetOwner myOwner; // 1 owner for each pet}class PetOwner {Pet [ ] myPets; // multiple pets for each owner}17UML → Java : Computer SystemUMLJavaUML → Java : Computer SystemUMLJavaclass Controller {}class SCSIController extends Controller {}18UML → Java : Computer SystemUMLJavaDesign code using all available information in UML…UML → Java : Computer SystemJavaclass CPU {Controller [ ] myCtlrs;}class Controller {CPU myCPU;}class SCSIController extends Controller {DiskDrive [ ] myDrives = new DiskDrive[4];}Class DiskDrive {SCSIController mySCSI;}19Java → UML : Printing SystemJavaclass Registry {PrintQueue findQueue();}class PrintQueue {List printJobs;Printer myPrinter;Registry myRegistry;void newJob();int length();Resources getResource();}Java → UML : Printing SystemJavaClass Printer {Resources myResources;Job curJob;void print();boolean busy();boolean on();}class Job {Job(Registry r) {…}}20Java → UML : Printing SystemUML SummaryGraphics modeling languageVisually represents design of software systemWe focused on class diagramsContents of a classRelationship between classesYou should be able toDraw UML class diagram given Java codeWrite Java code given UML class
View Full Document