Design and UML Class Diagrams | My Assignment Tutor

1Design and UMLClass DiagramsWEEK 71Big questionsWhat is UML?What is a UML class diagram?◦ What kind of information goes into it?◦ How do I create it?◦ When should I create it?22Design phasedesign: specifying the structure of how a softwaresystem will be written and function, withoutactually writing the complete implementationa transition from “what” the system must do, to“how” the system will do it◦ What classes will we need to implement a system thatmeets our requirements?◦ What fields and methods will each class have?◦ How will the classes interact with each other?3How do we design classes?class identification from project spec / requirements◦ nouns are potential classes, objects, fields◦ verbs are potential methods or responsibilities of a classCRC card exercises◦ write down classes’ names on index cards◦ next to each class, list the following:◦ responsibilities: problems to be solved; short verb phrases◦ collaborators: other classes that are sent messages by this class (asymmetric)UML diagrams◦ class diagrams (today)◦ sequence diagrams◦ …43Introduction to UMLUML: pictures of an OO system◦ programming languages are not abstract enough for OO design◦ UML is an open standard; lots of companies use itWhat is legal UML?◦ a descriptive language: rigid formal syntax (like programming)◦ a prescriptive language: shaped by usage and convention◦ it’s okay to omit things from UML diagrams if they aren’t needed byteam/supervisor/instructor5Uses for UMLas a sketch: to communicate aspects of system◦ forward design: doing UML before coding◦ backward design: doing UML after coding as documentation◦ often done on whiteboard or paper◦ used to get rough selective ideasas a blueprint: a complete design to be implemented◦ sometimes done with CASE (Computer-Aided Software Engineering) toolsas a programming language: with the right tools, code can be autogenerated and executed from UML◦ only good if this is faster than coding in a “real” language64UML class diagramsWhat is a UML class diagram?What are some things that are not represented in a UML class diagram?7 details of how the classes interact with each other algorithmic details; how a particular behavior isimplemented UML class diagram: a picture of the classes in anOO system, their fields and methods, andconnections between the classes that interact orinherit from each otherDiagram of one classclass name in top of box◦ write on top of interfaces’ names◦ use italics for an abstract class nameattributes (optional)◦ should include all fields of the objectoperations / methods (optional)◦ may omit trivial (get/set) methods◦ but don’t omit any methods from an interface!◦ should not include inherited methods85Class attributesattributes (fields, instance variables)◦ visibility name : type [count] = default_value◦ visibility: + public# protected– private~ package (default)/ derived◦ underline static attributes◦ derived attribute: not stored, but canbe computed from other attribute values◦ attribute example:– balance : double = 0.009Class operations / methodsoperations / methods◦ visibility name (parameters) : return_type◦ visibility: + public# protected– private~ package (default)◦ underline static methods◦ parameter types listed as (name: type)◦ omit return_type on constructors andwhen return type is void◦ method example:+ distance(p1: Point, p2: Point): double106Commentsrepresented as a folded note, attached to the appropriateclass/method/etc by a dashed line11Relationships btwn. classesgeneralization: an inheritance relationship◦ inheritance between classes◦ interface implementationassociation: a usage relationship◦ dependency◦ aggregation◦ composition127Generalization relationshipsgeneralization (inheritance) relationships◦ hierarchies drawn top-down with arrows pointingupward to parent◦ line/arrow styles differ, based on whether parent isa(n):◦ class:solid line, black arrow◦ abstract class:solid line, white arrow◦ interface:dashed line, white arrow◦ we often don’t draw trivial / obvious generalizationrelationships, such as drawing the Object class as aparent13Associational relationshipsassociational (usage) relationships1. multiplicity (how many are used)◦ *  0, 1, or more◦ 1  1 exactly◦ 2..4  between 2 and 4, inclusive◦ 3..*  3 or more2. name (what relationship the objects have)3. navigability (direction)148Multiplicity of associations15 one-to-one each student must carry exactly one ID card one-to-many one rectangle list can contain many rectanglesAssociation typesaggregation: “is part of”◦ symbolized by a clear white diamondcomposition: “is entirely made of”◦ stronger version of aggregation◦ the parts live and die with the whole◦ symbolized by a black diamonddependency: “uses temporarily”◦ symbolized by dotted line◦ often is an implementationdetail, not an intrinsic part ofthat object’s state16 1 1Engine Car aggregation LotteryTicket Randomdependency Page* Book composition19Class diagram example 117Class diagram example 218 DVD MovieVHS MovieVideo GameComposition Rental Item Rental InvoiceCheckout Screen0..1 1..*1 Customer1 SimpleAssociationClassAbstractClassSimpleAggregationGeneralizationMultiplicity10Class diagram example 319 StudentBodyStudent+ main (args : String[])+ toString() : String1 100– firstName : String– lastName : String– homeAddress : Address– schoolAddress : Address + toString() : String– streetAddress : String– city : String– state : String– zipCode : longAddress Tools for creating UML diags.Violet (free)◦ Rose◦ Paradigm UML Suite (trial)◦◦ (nearly) direct download link: are many others, but most are commercial)2011Class design exerciseConsider the case study in the assignment brief on your Moodle;◦ What classes are in this system? What are their responsibilities? Whichclasses collaborate?◦ Draw a class diagram for this system. Include relationships between classes(generalization and associational).21


Leave a Reply

Your email address will not be published. Required fields are marked *