The Unified Modeling Language (UML) is a well accepted way of describing
an object oriented design. The image below was generated in Rational Rose.
The diagram shows three classes: Time,
Clock, and AlarmClock.
The top rectangle in each class gives the class name; the middle
rectangle lists the data members of the class; and the bottom
rectangle lists the member functions of the class.
Figure 1: UML Diagram
In addition, UML describes the relationships between the classes.
The black diamond on the line connecting the Clock
class to the Time class indicates that an object
from the Time class is a member (theTime)
of the Clock class. (See also the line from the
AlarmClock class to the Time class.
The open arrow on the line going from the AlarmClock
class to the Clock class indicates that the
AlarmClock class inherits the Clock
class. The padlock in front of the data members indicates that they
are private data members. The #
symbol in front of theTime data member indicates
that it is protected. The minus symbol in front
of the alarm data member indicates that it is
private. If a data member has a plus symbol in front
of it, it indicates that the data member is public.
UML diagrams can be used to help visualize the relationships between
classes. In addition, tools like Rational Rose can be used to generate
C++ (or some other language like Java) code from the UML diagram.
Of course, it can't fill in all of the details associated with
the implementation, but it can automate a bunch of the busy work
associated with implementing the classes. The next section contains
the code generated from the UML diagram using Rational Rose.
1// Copyright (C) 1991 - 1999 Rational Software Corporation
2
3#if defined (_MSC_VER) && (_MSC_VER >= 1000)
4#pragma once
5#endif
6#ifndef _INC_TIME_3AE5E433032A_INCLUDED
7#define _INC_TIME_3AE5E433032A_INCLUDED
8
9class istream;
10class ostream;
11
12//##ModelId=3AE5E433032A
13class Time
14{
15private:
16 //##ModelId=3AE7142F0384
17 double second;
18 //##ModelId=3AE7141D0262
19 unsigned int minute;
20 //##ModelId=3AE71401010E
21 unsigned int hour;
22
23public:
24 //##ModelId=3AE71A490336
25 Time();
26
27 //##ModelId=3AE71A67024E
28 Time(const Time& orig);
29
30 //##ModelId=3AE71A46038E
31 virtual ~Time();
32
33 //##ModelId=3AE71A7102F0
34 Time& operator=(Time& rhs);
35
36 //##ModelId=3AE71ABA02B2
37 Time operator+(const Time& rhs) const;
38
39 //##ModelId=3AE71AFC00DC
40 Time operator+(int min) const;
41
42 //##ModelId=3AE71B1703C0
43 Time operator-(const Time& rhs) const;
44
45 //##ModelId=3AE71B20008C
46 Time operator-(int min) const;
47
48
49
50
51 //Three argument constructor that sets the hours,
52 //minutes, and seconds
53 //##ModelId=3AE7138103B6
54 Time(unsigned int hr, unsigned int min = 0, double sec = 0.0);
55
56 //Extracts a time from the input stream, is
57 //##ModelId=3AE7147A00A0
58 bool extract(istream& is);
59
60 //Inserts the object into the output stream, os
61 //##ModelId=3AE714AF00DC
62 void insert(ostream& os) const;
63
64};
65
66#endif /* _INC_TIME_3AE5E433032A_INCLUDED */
67
1// Copyright (C) 1991 - 1999 Rational Software Corporation
2
3#if defined (_MSC_VER) && (_MSC_VER >= 1000)
4#pragma once
5#endif
6#ifndef _INC_CLOCK_3AE5E604021C_INCLUDED
7#define _INC_CLOCK_3AE5E604021C_INCLUDED
8
9#include "Time.h"
10
11//##ModelId=3AE5E604021C
12class Clock
13{
14protected:
15 //##ModelId=3AE71BF500FA
16 Time theTime;
17
18public:
19 //##ModelId=3AE71C9F01CC
20 virtual ~Clock();
21
22 //##ModelId=3AE71CA0037C
23 Clock();
24
25 //##ModelId=3AE71CA10370
26 Clock(const Clock& orig);
27
28 //##ModelId=3AE71CD20000
29 Clock(Time& now);
30
31 //##ModelId=3AE71CB00000
32 Clock& operator=(Clock& rhs);
33
34 //Adds one minute to the current time
35 //##ModelId=3AE71CF40032
36 void incrementMinutes();
37
38 //subtracts one minute to the current time
39 //##ModelId=3AE71D0B0078
40 void decrementMinutes();
41
42 //Adds one hour to the current time
43 //##ModelId=3AE71D2F032A
44 void incrementHours();
45
46 //subtracts one hour to the current time
47 //##ModelId=3AE71D4A0186
48 void decrementHours();
49
50 //Sets the number of seconds to zero
51 //##ModelId=3AE71D630294
52 void resetSeconds();
53
54 //Displays the time
55 //##ModelId=3AE71D8600D2
56 void displayTime();
57
58
59};
60
61#endif /* _INC_CLOCK_3AE5E604021C_INCLUDED */
62
1// Copyright (C) 1991 - 1999 Rational Software Corporation
2
3#if defined (_MSC_VER) && (_MSC_VER >= 1000)
4#pragma once
5#endif
6#ifndef _INC_ALARMCLOCK_3AE5E629029E_INCLUDED
7#define _INC_ALARMCLOCK_3AE5E629029E_INCLUDED
8
9#include "Clock.h"
10#include "Time.h"
11
12//##ModelId=3AE5E629029E
13class AlarmClock
14: public Clock
15{
16public:
17 //##ModelId=3AE71E8A01B8
18 virtual ~AlarmClock();
19
20 //##ModelId=3AE71E8F0340
21 AlarmClock& operator=(AlarmClock& rhs);
22
23 //##ModelId=3AE71E98033E
24 AlarmClock(const AlarmClock& orig);
25
26 //Default constructor that will take the time, tm, and
27 //alarm, alm, and a bool, on, that indicates whether on
28 //not the alarm is set
29 //##ModelId=3AE71EC40302
30 AlarmClock(Time tm = Time(), Time alm = Time(), bool on = false);
31
32 //Adds one minute to the alarm time
33 //##ModelId=3AE71F21028A
34 void incrementAlarmMinutes();
35
36 //Adds one hour to the alarm time
37 //##ModelId=3AE71F3D0370
38 void incrementAlarmHours();
39
40 //##ModelId=3AE71F5C032A
41 void displayAlarm() const;
42
43 //Returns true if the alarm is on
44 //##ModelId=3AE71F740104
45 bool isAlarmOn() const;
46
47 //Turns the alarm on
48 //##ModelId=3AE71F9500A0
49 void alarmOn();
50
51 //Turns the alarm off
52 //##ModelId=3AE71FAC01F4
53 void alarmOff();
54
55private:
56 //##ModelId=3AE71E5701A4
57 bool willBuzz;
58
59 //##ModelId=3AE71E3B0082
60 Time alarm;
61
62};
63
64#endif /* _INC_ALARMCLOCK_3AE5E629029E_INCLUDED */
65
1// Copyright (C) 1991 - 1999 Rational Software Corporation
2
3#include "stdafx.h"
4#include <istream.h>
5#include <ostream.h>
6#include "Time.h"
7
8
9//##ModelId=3AE7138103B6
10Time::Time(unsigned int hr, unsigned int min, double sec)
11{
12 // TODO: Add your specialized code here.
13}
14
15//##ModelId=3AE7147A00A0
16bool Time::extract(istream& is)
17{
18 // TODO: Add your specialized code here.
19 return (bool)0;
20}
21
22//##ModelId=3AE714AF00DC
23void Time::insert(ostream& os) const
24{
25 // TODO: Add your specialized code here.
26}
27
28
29
30//##ModelId=3AE71A490336
31Time::Time() : hour(0), minute(0), second(0)
32{
33 // ToDo: Add your specialized code here and/or call the base class
34}
35
36//##ModelId=3AE71A67024E
37Time::Time(const Time& orig)
38{
39 // ToDo: Add your specialized code here and/or call the base class
40}
41
42//##ModelId=3AE71A46038E
43Time::~Time()
44{
45 // ToDo: Add your specialized code here and/or call the base class
46}
47
48//##ModelId=3AE71A7102F0
49Time& Time::operator=(Time& rhs)
50{
51 // ToDo: Add your specialized code here and/or call the base class
52
53 return rhs;
54}
55
56//##ModelId=3AE71ABA02B2
57Time Time::operator+(const Time& rhs) const
58{
59 // TODO: Add your specialized code here.
60 // NOTE: Requires a correct return value to compile.
61}
62
63//##ModelId=3AE71AFC00DC
64Time Time::operator+(int min) const
65{
66 // TODO: Add your specialized code here.
67 // NOTE: Requires a correct return value to compile.
68}
69
70//##ModelId=3AE71B1703C0
71Time Time::operator-(const Time& rhs) const
72{
73 // TODO: Add your specialized code here.
74 // NOTE: Requires a correct return value to compile.
75}
76
77//##ModelId=3AE71B20008C
78Time Time::operator-(int min) const
79{
80 // TODO: Add your specialized code here.
81 // NOTE: Requires a correct return value to compile.
82}
83
84
1// Copyright (C) 1991 - 1999 Rational Software Corporation
2
3#include "stdafx.h"
4#include "Clock.h"
5
6
7//##ModelId=3AE71C9F01CC
8Clock::~Clock()
9{
10 // ToDo: Add your specialized code here and/or call the base class
11}
12
13//##ModelId=3AE71CA0037C
14Clock::Clock()
15{
16 // ToDo: Add your specialized code here and/or call the base class
17}
18
19//##ModelId=3AE71CA10370
20Clock::Clock(const Clock& orig)
21{
22 // ToDo: Add your specialized code here and/or call the base class
23}
24
25//##ModelId=3AE71CD20000
26Clock::Clock(Time& now)
27{
28 // TODO: Add your specialized code here.
29}
30
31//##ModelId=3AE71CB00000
32Clock& Clock::operator=(Clock& rhs)
33{
34 // ToDo: Add your specialized code here and/or call the base class
35
36 return rhs;
37}
38
39//##ModelId=3AE71CF40032
40void Clock::incrementMinutes()
41{
42 // TODO: Add your specialized code here.
43}
44
45//##ModelId=3AE71D0B0078
46void Clock::decrementMinutes()
47{
48 // TODO: Add your specialized code here.
49}
50
51//##ModelId=3AE71D2F032A
52void Clock::incrementHours()
53{
54 // TODO: Add your specialized code here.
55}
56
57//##ModelId=3AE71D4A0186
58void Clock::decrementHours()
59{
60 // TODO: Add your specialized code here.
61}
62
63//##ModelId=3AE71D630294
64void Clock::resetSeconds()
65{
66 // TODO: Add your specialized code here.
67}
68
69//##ModelId=3AE71D8600D2
70void Clock::displayTime()
71{
72 // TODO: Add your specialized code here.
73}
74
75
1// Copyright (C) 1991 - 1999 Rational Software Corporation
2
3#include "stdafx.h"
4#include "AlarmClock.h"
5
6
7//##ModelId=3AE71E8A01B8
8AlarmClock::~AlarmClock()
9{
10 // ToDo: Add your specialized code here and/or call the base class
11}
12
13//##ModelId=3AE71E8F0340
14AlarmClock& AlarmClock::operator=(AlarmClock& rhs)
15{
16 // ToDo: Add your specialized code here and/or call the base class
17
18 return rhs;
19}
20
21//##ModelId=3AE71E98033E
22AlarmClock::AlarmClock(const AlarmClock& orig)
23{
24 // ToDo: Add your specialized code here and/or call the base class
25}
26
27//##ModelId=3AE71EC40302
28AlarmClock::AlarmClock(Time tm, Time alm, bool on) : willBuzz(false)
29{
30 // TODO: Add your specialized code here.
31}
32
33//##ModelId=3AE71F21028A
34void AlarmClock::incrementAlarmMinutes()
35{
36 // TODO: Add your specialized code here.
37}
38
39//##ModelId=3AE71F3D0370
40void AlarmClock::incrementAlarmHours()
41{
42 // TODO: Add your specialized code here.
43}
44
45//##ModelId=3AE71F5C032A
46void AlarmClock::displayAlarm() const
47{
48 // TODO: Add your specialized code here.
49}
50
51//##ModelId=3AE71F740104
52bool AlarmClock::isAlarmOn() const
53{
54 // TODO: Add your specialized code here.
55 return (bool)0;
56}
57
58//##ModelId=3AE71F9500A0
59void AlarmClock::alarmOn()
60{
61 // TODO: Add your specialized code here.
62}
63
64//##ModelId=3AE71FAC01F4
65void AlarmClock::alarmOff()
66{
67 // TODO: Add your specialized code here.
68}
69
70