DOC PREVIEW
UMD CMSC 132 - Object-Oriented Programming II

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC 132: Object-Oriented Programming IINelson Padua-PerezWilliam PughDepartment of Computer ScienceUniversity of Maryland, College ParkUML Class DiagramsRepresent the (static) structure of the systemGeneral In JavaName NameState VariablesBehavior MethodsRelationships Between ClassesAssociationPermanent, structural, “has a”Solid line (arrowhead optional)DependencyTemporary, “uses a”Dotted line with arrowheadGeneralizationInheritance, “is a”Solid line with open (triangular) arrowheadImplementationDotted line with open (triangular) arrowheadORAssociationDenotes permanent, structural relationship State of class A contains class BRepresented by solid line (arrowhead optional)Car and Engine classes know about each otherAssociations w/ Navigation InformationCan indicate direction of relationshipRepresented by solid line with arrowheadGas Pedal class knows about Engine class Engine class doesn’t know about Gas Pedal classAssociations w/ Navigation InformationDenotes “has-a” relationship between classes“Gas Pedal” has a “Engine”State of Gas Pedal class contains instance of Engine class ⇒⇒⇒⇒can invoke its methodsMultiplicity 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 moreMultiplicity 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 A BDependencyCaused 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 A BDependencyDependence may be caused byLocal variableParameterReturn valueExampleClass A { Class B {B Foo(B x) { …B y = new B(); …return y; …} } }Dependency ExampleClass Driver depends on Class CarGeneralizationDenotes inheritance between classesCan view as “is-a” relationshipRepresented by line ending in (open) triangleLaptop, Desktop, PDA inherit state & behavior from ComputersImplementationDenotes 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 organizationBanking systemHome heating systemPrinting systemUML Example – Veterinary SystemTry to read & understand UML diagramUML Example – Veterinary SystemTry to read & understand UML diagram• 1 or more Pets associated with 1 PetOwnerUML 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) ControllerUML Example – Banking SystemTry to read & understand UML diagramUML Example – Banking System• 1 Bank associated with 0 or more Accounts• Checking, Savings, MoneyMarket are AccountsUML 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 ThermostatUML 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 SystemUMLJavaUML →→→→ 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}UMLJava →→→→ 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}UML →→→→ Java : Computer SystemUMLJavaUML →→→→ Java : Computer SystemUMLJavaclass Controller {}class SCSIController extends Controller {}UML →→→→ 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;}Java →→→→ 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) {…}}Java →→→→ 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

UMD CMSC 132 - Object-Oriented Programming II

Documents in this Course
Notes

Notes

8 pages

Recursion

Recursion

12 pages

Sorting

Sorting

31 pages

HTML

HTML

7 pages

Trees

Trees

19 pages

HTML

HTML

18 pages

Trees

Trees

19 pages

Honors

Honors

19 pages

Lecture 1

Lecture 1

11 pages

Quiz #3

Quiz #3

2 pages

Hashing

Hashing

21 pages

Load more
Download Object-Oriented Programming II
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object-Oriented Programming II and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object-Oriented Programming II 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?