class design question

S

SB

Can anyone provide any insight/advice on how to take a problem (academic
assignment) and figure out what the classes should be? I have an assignment
that is basically a doctors scheduling program, i.e. for three doctors show
their schedule for the month of surgies, lectures and free time. It also
lets patients schedule appointments in the free time slots.
My problem is not being able to determine what the classes and how many of
them there should be. I know this is open ended, as each programmer might
see it differently and have different classes and not the same number of
classes as the next programmer. I would just like to know if there are any
guidelines to follow for breaking a problem down into classes.

Thanks in advance!
 
A

Alf P. Steinbach

* "SB said:
Can anyone provide any insight/advice on how to take a problem (academic
assignment) and figure out what the classes should be? I have an assignment
that is basically a doctors scheduling program, i.e. for three doctors show
their schedule for the month of surgies, lectures and free time. It also
lets patients schedule appointments in the free time slots.
My problem is not being able to determine what the classes and how many of
them there should be. I know this is open ended, as each programmer might
see it differently and have different classes and not the same number of
classes as the next programmer. I would just like to know if there are any
guidelines to follow for breaking a problem down into classes.

There are always guidelines, but if this problem could be described by easy to
follow rules then it could be automated, and you wouldn't be asked to do it.

Best advice: stop thinking about things you don't grok (classes) and start
analyzing how this works in real life (on paper) and start coding (on a computer).

Be prepared to throw away everything you've done at least once and hopefully also
twice and thrice; -- _then_ you're getting somewhere.



PS: Also, please post to a relevant group. This answer is cross-posted to
[comp.programming], and follow-up is set to [comp.programming]. You're
off-topic in [comp.lang.c++].
 
C

Cy Edmunds

SB said:
Can anyone provide any insight/advice on how to take a problem (academic
assignment) and figure out what the classes should be? I have an assignment
that is basically a doctors scheduling program, i.e. for three doctors show
their schedule for the month of surgies, lectures and free time. It also
lets patients schedule appointments in the free time slots.
My problem is not being able to determine what the classes and how many of
them there should be. I know this is open ended, as each programmer might
see it differently and have different classes and not the same number of
classes as the next programmer. I would just like to know if there are any
guidelines to follow for breaking a problem down into classes.

Thanks in advance!

That's a pretty general question. I would say a well designed class
shouldn't contain two things that really have nothing to do with each other.
(Sounds simple, doesn't it?) I would also say it is better to avoid member
functions which could have been written entirely using the rest of the
interface. It's better for encapsulation if these "helper functions" are
written as standalone functions. Don't write get/set functions for each data
member. You should be able to set the data values using the constructor.
Don't use operator new() unless you have to. If you need a destructor, a
copy constructor, or an assignment operator you almost certainly need all
three. (For the assignment you just described you should be able to avoid
any of these.) Use standard library containers such as std::vector and
std::string rather than their C language counterparts.

Good luck.
 
J

John Harrison

SB said:
Can anyone provide any insight/advice on how to take a problem (academic
assignment) and figure out what the classes should be? I have an assignment
that is basically a doctors scheduling program, i.e. for three doctors show
their schedule for the month of surgies, lectures and free time. It also
lets patients schedule appointments in the free time slots.
My problem is not being able to determine what the classes and how many of
them there should be. I know this is open ended, as each programmer might
see it differently and have different classes and not the same number of
classes as the next programmer. I would just like to know if there are any
guidelines to follow for breaking a problem down into classes.

Thanks in advance!

A common piece of advice is that the nouns are classes and the verbs are
methods.

So on that basis I would say the only dead certs for classes are Doctor.
Some methods on Doctor would be book_surgery, book_lecture, print_schedule,
make_appointment.

Some possibles for classes would be Patient, TimePeriod, Schedule, but from
the description above I don't think I would use any of those.

john
 
A

anon luker

There are a lot of factors that you need to consider (or if your
assignment is as flaky as most of the ooa&d classes we used to have
forced upon us, make up and state your own constraints, then defend
them). I would probably start by looking at the largest and smallest
discrete time segments. Those are probably going to make good
classes. Do visits ever stretch between months? Probably not, so a
month might be a good container class (espescially since it is
mentioned in your assignment and it is convenient for fiscal etc
analysis). On the other end of the time spectrum... do doctors always
allocate the same amount of time for each visit? Are there
constraints, such as limited waiting areas or observation rooms or
whatever? Do we have to consider medical histories or lab usage when
scheduling patients? These concerns are also going to shape your
modelling. Assuming the office keeps regular hours and your only
constraint is time, then you are probably going to want month, day,
and scheduled_visit objects for each doctor with doctor as either an
enumerated type or a part of a global wrapper class.

hope this got your juices flowing.
 
T

Thomas Matthews

SB said:
Can anyone provide any insight/advice on how to take a problem (academic
assignment) and figure out what the classes should be? I have an assignment
that is basically a doctors scheduling program, i.e. for three doctors show
their schedule for the month of surgies, lectures and free time. It also
lets patients schedule appointments in the free time slots.
My problem is not being able to determine what the classes and how many of
them there should be. I know this is open ended, as each programmer might
see it differently and have different classes and not the same number of
classes as the next programmer. I would just like to know if there are any
guidelines to follow for breaking a problem down into classes.

Thanks in advance!

If you're really eager, I suggest you research on "use cases".
Use Cases are a tool to help extract the requirements out of
a problem domain.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,431
Latest member
ElyseG3173

Latest Threads

Top