Slide 1What will we learn?IntroductionSlide 4UML: Design Class Diagram (DCD)Classifiers, AttributesUML: Notating AttributesAttributes As AssociationsUML: Attributes as AssociationsAttributes: Text versus AssociationsUML: Attributes as AssociationsAttributes: ListsOperations and MethodsMethod Notation in UMLKeywordsAbstract ClassesDependency in UMLDependency in UMLDependency in UMLDependency LabelsSlide 21Composition and AggregationComposition: ExampleComposition: ExampleConstraints and Qualified AssociationsQualified AssociationAssociation ClassesMore on UML DiagramsTemplatesSlide 30Slide 31Takeaways from Chapter 16Next …Object-Oriented Analysis and DesignCHAPTERS 16: UML CLASS DIAGRAMS1What will we learn?UML Class Diagrams – What are they, how to create them2IntroductionUML provides the tools for creating general class diagrams, i.e. static object modeling, that can be used to create Domain Models or software class diagramsWe will look in more detail at the UML notation that can be used, irrespective of the perspective (conceptual or software class)Note that UML provides a set of diagraming tools, most of which are optional to useStandardized diagram language, makes it easier to communicate designsThe next slide gives an overview of the concepts we will be discussing in this lecture34java.awt::Fontorjava.awt.Fontplain : Int = 0 { readOnly }bold : Int = 1 { readOnly }name : Stringstyle : Int = 0...getFont(name : String) : FontgetName() : String...«interface»Runnablerun()- ellipsis “…” means there may be elements, but not shown- a blank compartment officially means “unknown” but as a convention will be used to mean “no members”SubclassFoo...run()...SuperclassFooorSuperClassFoo { abstract }- classOrStaticAttribute : Int+ publicAttribute : String- privateAttributeassumedPrivateAttributeisInitializedAttribute : Bool = trueaCollection : VeggieBurger [ * ]attributeMayLegallyBeNull : String [0..1] finalConstantAttribute : Int = 5 { readOnly }/derivedAttribute + classOrStaticMethod()+ publicMethod()assumedPublicMethod()- privateMethod()# protectedMethod()~ packageVisibleMethod()«constructor» SuperclassFoo( Long )methodWithParms(parm1 : String, parm2 : Float)methodReturnsSomething() : VeggieBurgermethodThrowsException() {exception IOException}abstractMethod()abstractMethod2() { abstract } // alternatefinalMethod() { leaf } // no override in subclasssynchronizedMethod() { guarded } 3 common compartments1. classifier name2. attributes3. operationsinterface implementation andsubclassingFruit......PurchaseOrder......1association with multiplicitiesdependency officially in UML, the top format is used to distinguish the package name from the class nameunofficially, the second alternative is commonorderan interface shown with a keywordUML: Design Class Diagram (DCD)5Register...endSale()enterItem(...)makePayment(...)SaletimeisComplete : Boolean/totalmakeLineItem(...)Register...SaletimeisComplete : Boolean/totalCaptures111Domain Modelconceptual perspectiveDesign ModelDCD; software perspectivecurrentSaleClassifiers, AttributesA UML classifier is a model element that describes behavioral and structure features Think of classes or interfacesAttributes may also be called structural propertiesAttributes may be displayed in several ways in a UML diagram:Text in a class boxOn an association lineBoth of the aboveFull format for attribute text notation (note most items are optional):Visibility name : type multiplicity = default {property-string}Note that Visibility is the +- notation we saw earlier (+ public, - private)6UML: Notating Attributes7Register......Sale......1RegistercurrentSale : Sale...Sale......using the attribute text notation to indicate Register has a reference to one Sale instanceusing the association notation to indicate Register has a reference to one Sale instanceOBSERVE: this style visually emphasizes the connection between these classescurrentSaleRegistercurrentSale : Sale...Sale......1thorough and unambiguous, but some people dislike the possible redundancycurrentSaleAttributes As AssociationsNotice that there are subtle differences between the conceptual perspective (Domain Model) and software perspective (Design Model) for attributes that are defined as associationsFor DCDs, there is usually A navigability arrow A multiplicity at the target end, but not the sourceA role nameNo association name8UML: Attributes as Associations9the association name, common when drawing a domain model, is often excluded (though still legal) when using class diagrams for a software perspective in a DCDRegisterid: Int...Saletime: DateTime...1currentSaleRegisterid : IntSaletime : DateTimeCaptures-current-sale11UP Domain Modelconceptual perspectiveUP Design ModelDCDsoftware perspectiveAttributes: Text versus AssociationsWe explored the idea of data type objects earlier (Domain Models)Data types referred to objects for which individual identity is not importantRecall a Person object versus a Name data typeOne guideline is to use the text for data types (basically primitive types) and associations for more complicated classesNote that this is a diagram preference – does not matter in the final code10UML: Attributes as Associations11Registerid: Int...Saletime: DateTime...1applying the guideline to show attributes as attribute text versus as association linesStoreaddress: Addressphone: PhoneNumber...1Register has THREE attributes:1. id2. currentSale3. locationcurrentSalelocationAttributes: ListsHow do we notate a list of attributes, e.g. an ArrayList in Java?12notice that an association end can optionally also have a property string such as {ordered, List}Saletime: DateTime...SalesLineItem......1..*lineItems{ordered, List}Saletime: DateTimelineItems : SalesLineItem [1..*] orlineItems : SalesLineItem [1..*] {ordered}...SalesLineItem......Two ways to show a collection attribute“Note” SymbolOperations and MethodsOperations are usually displayed in the class box with the notation:visibility name (parameter-list) {property-string}Sometime a return-type is value is addedAssume public if no visibility is shownAn operation is a declaration (name, parameters, return type, exceptions list)A method is an implementation of an operation in sequence diagrams, may show the details and sequence of messages In class diagram, usually include some pseudo-code in a note with the <<method>> tag13Method Notation in UML14Register...endSale()enterItem(id,
View Full Document