Design - Classes

Design - Classes

What is UML? A modeling language standardized by the OMG (Object Management Group), and widely used in OO analysis and design A modeling language is a visual language for representing software blueprints Latest version is 2.0 CS 3500 UML provides a standard notation, semantics for a set of OO abstractions L03A - 1 UML Overview UML defines a visual representation of a concept Everything that is defined in this has meaning Just like when writing code, you use () or , or + to represent something Same is true in UML

So, be careful of the types of arrows, boxes, etc. that you use Be careful of where you put other symbols Remember that there is a REAL syntax defined for UML You cant just write/draw whatever you like Our focus reading UML Class diagrams Next semester, writing them and other diagrams CS 3500 L03A - 2 UML Class Class name name Data members (attributes) Instance methods -x: double -y: double -z: double

-n: int +name() +method1(:double):double +method2():bool +classMethod() Class method (static) These compartments are optional. But if you need methods, then you have to have at least empty data member compartment. Return types Arguments Important if something isnt specified, then that doesnt necessarily mean that it isnt there. For example, does name take an argument or not, does it return a value? CS 3500 L03A - 3 Class Attributes Attributes are the instance and class data members Class data members (underlined) are shared between all instances

(objects) of a given class (think static). Data types shown after ":" Visibility shown as + public private # protected CS 3500 Attribute compartment Name -instanceDataMember: type -classDataMember: type +Name() +Name(:Name) +operation() +classMethod Attribute Model visibility name : type multiplicity = default {property-string} L03A - 4 Class Operations Operations are the class methods with their argument and return types

Public (+) operations define the class interface Class methods (underlined) have only access to class data members, no need for a class instance (object) Name -instanceDataMember: type -classDataMember: type +Name() +Name(:Name) +operation() +classMethod Parameter List Operations direction name: type = default compartment Direction Model Operations Model direction in, out, inout visibility name (parameter-list) : return-type {property-string} CS 3500 L03A - 5 Multiplicity - 1 Indicates how many objects may fill the property

1 exactly one 0 .. 1 may or may not have one * zero or more n .. m from n to m where n < m Default is [1] But it is best to not use default even if value is 1 to make it clear CS 3500 Question if you indicate that something is a n..m multiplicity, then how is this realized? L03A - 6 Unary Association A knows about B, but B knows nothing about A UML Comment A

B -myB: B +service() +doSomething() These two diagrams are identical in what they mean. Void doSomething() { myB.service(); } A +doSomething() -myB 1 B +service() Arrow shows direction of association in direction of dependency

CS 3500 L03A - 7 Unary Association IS an Attribute Exactly the same as an attribute Did you hear me? Exactly the same!!! Solid line (source to target) Name goes at the target end, plus multiplicity It is WRONG to include both an association and a attribute of the same thing That implies that BOTH exist at the same time What is the difference between a unary association (line) and an attribute? IT IS THE SAME THING!!!!! Dont forget!!!! CS 3500 L03A - 8

Binary Association Binary association: both classes know each other A +doSomething() void doSomething() { myB.service(); } -myA -myB 1 1 B +service() +operation() void operation() { myA.service(); } Usually "knows about" means a pointer or reference Other methods possible: method argument, tables, database, ... Implies dependency cycle CS 3500

L03A - 9 Dependency Weak relationships (also transitory): Class A simply knows of class B E.g., a method in A creates and immediately returns an object of class B That is: a change in one may force changes in the other although there is no explicit association between them. A CS 3500 B L03A - 10 Generalization (Inheritance) A -myX: double +setX(:double) +getX():double

Base class or super class Arrow shows direction of dependency B +operation() Derived class or subclass public class B : A { } CS 3500 L03A - 11 Aggregation Aggregation = Association with "whole-part" relationship Box +doSomething() void doSomething() { aContent.service(); .. } CS 3500

aModule 1 Content +service() Shown by hollow diamond at the "whole" side No lifetime control implied L03A - 12 Composition Composition = Aggregation with lifetime control Car +speed(): double Wheel wheels 4 +type double speed() { wheels[1] .. wheels[3] }

Lifetime control: construction and destruction controlled by "owner" call constructors and destructors (or have somebody else do it) CS 3500 Shown by filled diamond at the "owner" side Lifetime control implied Lifetime control can be transferred L03A - 13 Composition/Aggregation Notations whole MovieTheater 0..* 0..* part CS 3500 1

1 BoxOffice part composition aggregation Movie L03A - 14 Describe This Diagram Owner Vehicle - myVehicles - myOwner + firstName : string + weight : int + lastName : string + topSpeed : int 0..* 1 + phoneNumber : string + VIN : string + getOwner ( ) + contactOwner ( [in] message : string ) : bool + getName ( ) : string

Car + modelType : string + maxPassengers : int + addRepairNote ( [in] note : string ) : bool Motorcycle + modelType : string - wheels Wheel 2 + maxMileage : int - wheels 4 CS 3500 L03A - 15

Recently Viewed Presentations

  • Compounds and Chemical Bonds Part 1

    Compounds and Chemical Bonds Part 1

    For the purpose of making chemical bonds the valence shell is the only thing that matters. 8 is a magic number. For elements Boron (5) or greater, the valence shell is considered full if it has 8 electrons. ... Lewis...
  • Cleveland Harrison McKinley REVIEW GAME 1. During McKinleys

    Cleveland Harrison McKinley REVIEW GAME 1. During McKinleys

    Ordered that the flag be flown over the White House, as well as other federal buildings. A. Cleveland. ... One of the heated issues of Cleveland's presidency was the continuing debate over money supply in America and the distribution of...
  • Chapter 4

    Chapter 4

    A conditional jump instruction branches to a label when specific register or flag conditions are met. Specific jumps: JB, JC - jump to a label if the Carry flag is set. JE, JZ - jump to a label if the...
  • Table of Contents 1. 2. 3. 4. 5.

    Table of Contents 1. 2. 3. 4. 5.

    The Plagiarism Spectrum is a guide that Turnitin developed to help educators, students, academics, and writers recognize the various forms of plagiarism. This spectrum moves plagiarism beyond the black-and-white definition of "literary theft" to one that captures the nuances of...
  • Jodi Arias - Seneca Valley School District

    Jodi Arias - Seneca Valley School District

    Claimed her parents abused her beginning at age 7. ... She was known to be incredibly jealous when Travis spoke to other women. ... Gunshot wound to his head, kill shot. Slit his throat from ear to ear. 27 stab...
  • Parts of Speech

    Parts of Speech

    Parts of Speech (Lexical Categories) Parts of Speech Nouns, Verbs, Adjectives, Prepositions, Adverbs (etc.) The building blocks of sentences The [Nsun] shines too brightly in Tucson *[VWill glow] shines too brightly in Tucson Also called: Lexical Categories, Syntactic Categories.
  • ATEC 4371.001 Procedural Animation

    ATEC 4371.001 Procedural Animation

    Dr. Midori Kitagawa. Procedural Animations . Two major categories in procedural animation are: Physics-based simulations deal with things that are not alive. ... Extracts a polygon mesh of an iso-surface from voxels (or an implicit function).
  • Dias nummer 1 - peterwidell.com

    Dias nummer 1 - peterwidell.com

    Nu kan alle beregne online, hvad man skal gøre for at forbrænde de ekstra kalorier. Kender du det? ... må ikke deles, fx gear, ikke ge-ar, dou-che, ikke do-uche, spa-ghetti, ikke spag-hetti, bol-sje, ikke bols-je (se NG s. 163). To...