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

  • Destiny One - Temple University

    Destiny One - Temple University

    ON THE DAY OF your Skype interview, please be sure that your microphone and speakers are set properly. Please also ensure you have a strong/good internet connection and are in a quiet place. We will ask that you scan the...
  • WO Recruiting Warrant Officer Strength Brief CW3 Robyn

    WO Recruiting Warrant Officer Strength Brief CW3 Robyn

    Rank wise: Warrant officers fall between the highest enlisted rank, and the lowest officer rank. A WO1 outranks a SGM and a CW5 is outranked by a 2LT. However you would not see a SGM work for a WO1 just...
  • Average Atomic Mass - New Providence School District

    Average Atomic Mass - New Providence School District

    Average Atomic Mass Masses of Atoms A scale designed for atoms gives their small atomic masses in atomic mass units (amu) An atom of 12C was assigned an exact mass of 12.00 amu Relative masses of all other atoms was...
  • The Washington State Migrant Education Health Program

    The Washington State Migrant Education Health Program

    Successfully completes an ESL class . Successfully completes an ABE or high school equivalency certificate coursework . Passes one or more tests/benchmarks that satisfy State Board graduation requirements . Successfully completes a grade level curriculum in a core academic subject...
  • Agenda Week 1: 16 September 2003

    Agenda Week 1: 16 September 2003

    Psychology and Property Purchase Decisions Clare Branigan June 2009
  • The Structure of the Atmosphere

    The Structure of the Atmosphere

    The earth and its atmosphere receive heat energy from the sun. The atmospheric heat budget of the Earth depends on the balance between incoming solar radiation (insolation) and outgoing radiation from the planet . Geological records show that, on average,...
  • 2 Corinthians

    2 Corinthians

    2 Co 5.1-21 - Context of Book . Paul wrote this letter to the Corinthians to comfort them and to defend his apostleship among them, so they would continue their participation with him, in his sphere of authority.
  • Prince of Peace Lutheran Church A family of

    Prince of Peace Lutheran Church A family of

    Interest in joining Long Range Planning / Equipping please contact Roger McQuistion, Steve Mayer, Nancy Scheruerman, Cindy Romnek, Sue Evers or Kerry Arnold Questions? Author