Download presentation
Presentation is loading. Please wait.
Published byArron Cook Modified over 9 years ago
1
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
2
Mastering Object Oriented Analysis and Design with UML Copyright © 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
3
Mastering Object Oriented Analysis and Design with UML Copyright © 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
4
Mastering Object Oriented Analysis and Design with UML Copyright © 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
5
Mastering Object Oriented Analysis and Design with UML Copyright © 2003 Rational Software, all rights reserved 5 > MathPack randomSeed : long = 0 -randomSeed : long = 0 -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
6
Mastering Object Oriented Analysis and Design with UML Copyright © 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
7
Mastering Object Oriented Analysis and Design with UML Copyright © 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
8
Mastering Object Oriented Analysis and Design with UML Copyright © 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
9
Mastering Object Oriented Analysis and Design with UML Copyright © 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
10
Mastering Object Oriented Analysis and Design with UML Copyright © 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..4primaryCourses Association Multiplicity
11
Mastering Object Oriented Analysis and Design with UML Copyright © 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..4 0..* primaryCourses PrimaryScheduleOfferingInfo - grade: char = I alternateCourses 0..20..* ScheduleCourseOffering 11 0..4 0..20..* alternateCourses primaryCourseOfferingInfo PrimaryScheduleOfferingInfo - grade: char = I Design Decisions
12
Mastering Object Oriented Analysis and Design with UML Copyright © 2003 Rational Software, all rights reserved 12 Course prerequisites 0..* class Course { public: Course(); ~Course(); private: UnboundedSetByReference prerequisites; }; Reflexive Associations
13
Mastering Object Oriented Analysis and Design with UML Copyright © 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 the_Schedule; }; Aggregation
14
Mastering Object Oriented Analysis and Design with UML Copyright © 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 the_Schedule; }; Composition
15
Mastering Object Oriented Analysis and Design with UML Copyright © 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
16
Mastering Object Oriented Analysis and Design with UML Copyright © 2003 Rational Software, all rights reserved 16 Amphibious Vehicle Water Vehicle Land Vehicle {overlapping} #include “LandVehicle.h” #include “WaterVehicle.h” class AmphibiousVehicle : public LandVehicle, private WaterVehicle {... }; > #include “Vehicle.h” class WaterVehicle : virtual public Vehicle {... }; Multiple Inheritance
17
Mastering Object Oriented Analysis and Design with UML Copyright © 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
18
Mastering Object Oriented Analysis and Design with UML Copyright © 2003 Rational Software, all rights reserved 18 #include “Set.h” typedef Set mySetOfFloats; template class Set { public: void insert (T anElement); void remove (T anElement); }; Set T, n:int > mySetOfFloats insert(T) remove(T) Parameterized Class
19
Mastering Object Oriented Analysis and Design with UML Copyright © 2003 Rational Software, all rights reserved 19 Interfaces and Realizes Relationships Schedule > Serializable >
20
Mastering Object Oriented Analysis and Design with UML Copyright © 2003 Rational Software, all rights reserved 20 CourseCatalog > ICourseCatalog getCourseOfferings() : CourseOfferingList Subsystems
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.