mastering object-oriented analysis and design with uml appendix: uml to c++ mapping mastering...

20
Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping

Upload: arron-cook

Post on 28-Dec-2015

232 views

Category:

Documents


11 download

TRANSCRIPT

Page 1: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object-Oriented Analysis and Design with UML

Appendix: UML to C++ Mapping

Mastering Object-Oriented Analysis and Design with UML

Appendix: UML to C++ Mapping

Page 2: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 2

// Notes will be used in the// rest of the presentation// to contain C++ code for// the attached UML elements

class Course{public: Course(); ~Course();};

Course

Mapping Representation: Notes

Page 3: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 3

class Student{

public: void addSchedule (theSchedule: Schedule, forSemester: Semester); int hasPrerequisites(forCourseOffering: CourseOffering);

protected: int passed(theCourseOffering: CourseOffering);

private: char* name;};

Visibility for Attributes and Operations

Student

- name : char*

+ addSchedule (theSchedule: Schedule, forSemester: Semester)+ hasPrerequisites(forCourseOffering: CourseOffering) : int# passed(theCourseOffering: CourseOffering) : int

Page 4: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 4

class Student {

public: static int getNextAvailID();

private: static int nextAvailID = 1;};

Student

- nextAvailID : int = 1

+ getNextAvaiIID() : int

Class Scope Attributes and Operations

Page 5: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 5

<<utility>> MathPack

-randomSeed : long = 0randomSeed : long = 0-pi : double = 3.14159265358979-pi : double = 3.14159265358979

+sin (angle : double) : double+cos (angle : double) : double+random() : double

class MathPack {public: static double sin(double angle); static double cos(double angle); static double random();private: static long randomSeed = 0; static double pi = 3.14159265358979;};

void main(void). . . myCos = MathPack::cos(90.0);. . .

Utility Class

A grouping of “free” attributes and operations

Page 6: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 6

Outer

Outer::Inner

class Outer{public: class Inner { public: Inner(); ~Inner(); }; Outer(); ~Outer();};

Nested Class

Hide a class that is relevant only for implementation

Page 7: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 7

Schedule

Student

#include “Schedule.h”

class Student{public: Student(); ~Student();private: Schedule* theSchedule;};

class Student;

class Schedule{public: Schedule(); ~ Schedule();private Student* theStudent;};

Associations

Bi-directional associations

Page 8: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 8

Schedule

Student

#include “Schedule.h”

class Student{public: Student(); ~Student();private: Schedule * theSchedule;};

class Schedule{public: Schedule(); ~ Schedule();};

Association Navigability

Uni-directional associations

Page 9: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 9

Professor

CourseOffering

instructor

#include "Company.h"

class Professor {public: Professor(); ~ Professor ();private: CourseOffering* theCourseOffering;};

class Professor;

class CourseOffering {public: CourseOffering(); ~ CourseOffering ();private: Professor* instructor;};

Association Roles

Page 10: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 10

CourseOffering

Schedule

#include “CourseOffering.h”

class Schedule{public: Schedule(); ~ Schedule(); private: CourseOffering* primaryCourses[4];};

class CourseOffering{public: CourseOffering(); ~ CourseOffering();};

0..4 primaryCourses

Association Multiplicity

Page 11: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 11

Schedule

class CourseOffering;

class PrimaryScheduleOfferingInfo {public: PrimaryScheduleOfferingInfo(); ~ PrimaryScheduleOfferingInfo (); const CourseOffering * get_the_CourseOffering() const; void set_the_CourseOffering(CourseOffering *const toValue);private: const char get_Grade() const; void set_Grade(const char toValue); char value = ‘I’; CourseOffering *theCourseOffering;};

Association Class

CourseOffering

0..40..*

primaryCourses

PrimaryScheduleOfferingInfo

- grade: char = I

alternateCourses

0..20..*

0..*

Schedule CourseOffering

11 0..4

0..20..*

alternateCourses

primaryCourseOfferingInfo PrimaryScheduleOfferingInfo

- grade: char = I

Design Decisions

Page 12: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 12

Course

prerequisites

0..*

class Course {public: Course(); ~Course();private: UnboundedSetByReference<Course> prerequisites;};

Reflexive Associations

Page 13: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 13

Schedule

Student

class Schedule{public: Schedule(); ~ Schedule();};

0..*

1

#include “Schedule.h”

class Student{public: Student(); ~Student();private UnboundedSetByReference<Schedule> the_Schedule;};

Aggregation

Page 14: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 14

Schedule

Student

class Schedule{public: Schedule(); ~ Schedule();};

0..*

1

#include “Schedule.h”

class Student{public: Student(); ~Student();private UnboundedSetByValue<Schedule> the_Schedule;};

Composition

Page 15: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 15

GroundVehicle

class Truck : public GroundVehicle{public: float tonnage; void getTax();};

class GroundVehicle{public: int licenseNumber; void register();};

+licenseNumber: int

+register()

Truck

+tonnage: float

+getTax()

Generalization

Page 16: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 16

Amphibious Vehicle

Vehicle

WaterVehicle

LandVehicle

{overlapping}

#include “LandVehicle.h”#include “WaterVehicle.h”

class AmphibiousVehicle : public LandVehicle, private WaterVehicle{ . . .};

<<private>>

<<virtual>> <<virtual>>

#include “Vehicle.h”

class WaterVehicle : virtual public Vehicle{ . . .};

Multiple Inheritance

Page 17: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 17

class Animal {public: virtual void talk() = 0;};

Animal{abstract}

Lion

+talk()

Tiger

+talk()

#include "Animal.h"

class Tiger : public Animal{public: Tiger(); ~Tiger(); void talk();};

+talk() {abstract}

Abstract Class

Page 18: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 18

#include “Set.h”

typedef Set<float, 100> mySetOfFloats;

template <class T, int n>class Set {public: void insert (T anElement); void remove (T anElement);};

SetT, n:int

<<bind>>

mySetOfFloats

insert(T)remove(T)

<float, 100>

Parameterized Class

Page 19: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 19

Interfaces and Realizes Relationships

Schedule<<entity>>

Serializable<<Interface>>

Page 20: Mastering Object-Oriented Analysis and Design with UML Appendix: UML to C++ Mapping Mastering Object-Oriented Analysis and Design with UML Appendix: UML

Mastering Object Oriented Analysis and Design with UMLCopyright © 2003 Rational Software, all rights reserved 20

CourseCatalog<<subsystem>>

ICourseCatalog

getCourseOfferings() : CourseOfferingList

Subsystems