Class design question

A

Angus Comber

Hello

I am attempting to build a set of classes which handle telephony. Basically
the handling of phone calls.

My design currently has two main classes - one dealing with the device and
the other with actual calls. So you could say I have a device class and a
calls class. The device here is a telephone handset basically. Telephones
connected to business switchboards can hanlde more than one call at a time -
eg you can have one call on hold while you talk to someone on another call -
there is an active call and a held call.

So is the best bet to have two classes: device class and calls class.
Should calls class inherit from devices class?

With telephony much of the activity is generated from the phone. So a phone
could suddenly receive a call. I want to then pass the activity information
to a program using this class. I am a little unsure as to how I get the
call activity information to my program?

For example, my calls class might have a OnIncomingCall function. But how
does my program 'receive' this notification? I can of course have a
OnIncomingCall function in calls class but if I start my telephone program
by calling devices class - how will my calling program know a call has
happened? Or will the Devices class 'have' a OnIncomingCall function
because of the 'child' Calls class function OnIncomingCall.

I realise this is all probably very basic. But would really appreciate some
guidance.

Angus Comber
(e-mail address removed)
 
M

Mark A. Gibbs

Angus said:
So is the best bet to have two classes: device class and calls class.
Should calls class inherit from devices class?

I am not an OO or a software design expert, but since I see no other
answers to your post, let me offer one.

I would say no. Inheritance would suggest that a call IS_A device, when
it is not. A call is a call, a device is a device. A device may HAVE_A
call or two - that suggests to me that a device class may have call
objects as members. However, a call would probably need to be able to
send messages to the device it is on, so it would need a reference to
the owning device class. This actually makes things a little sticky with
regards to ownership and lifetime issues of call objects.
With telephony much of the activity is generated from the phone. So a phone
could suddenly receive a call. I want to then pass the activity information
to a program using this class. I am a little unsure as to how I get the
call activity information to my program?

Well, in portable C++, about the only solution that I can think of is to
poll the device. In other words, at some level you would have something
very roughly like:

while(true)
{
// Check the device for any incoming calls
}

And loop until you reach some exit condition.

In practice, that's not a great solution, but it's a jumping off point.
You would probably use a dedicated thread to poll the device, or some
kind of operating system callback - whatever facilities are provided by
your implementation.

The thing you have to think about is - and I have no way of knowing -
where do calls come from? Something has to tell your program that a call
has arrived. Does the phone send a message via the serial port? In that
case, poll the serial port (or, if your OS supports it, use callbacks
and/or hardware interrupts). That's outside the scope of C++.
For example, my calls class might have a OnIncomingCall function. But how
does my program 'receive' this notification? I can of course have a
OnIncomingCall function in calls class but if I start my telephone program
by calling devices class - how will my calling program know a call has
happened? Or will the Devices class 'have' a OnIncomingCall function
because of the 'child' Calls class function OnIncomingCall.

First question (using the standard C++ only solution):

// pseudocode
while (program is running)
check device for incoming calls
if (there is a new call)
OnIncomingCall(device call is on, new call)
end if
end while

Now, for the rest. I would not recommend putting OnIncomingCall in your
call class. Calls don't have incoming calls, devices do. Think of each
class in terms of what its objects are, has and do.
I realise this is all probably very basic. But would really appreciate some
guidance.

Basic in some ways, but not in others. Your final solution will depend
on how your program can get information about whether or not a call has
come in. That is beyond the scope of comp.lang.c++. But once your
program can be aware of calls, we can help from there.

mark
 
J

John Harrison

Angus Comber said:
Hello

I am attempting to build a set of classes which handle telephony. Basically
the handling of phone calls.

My design currently has two main classes - one dealing with the device and
the other with actual calls. So you could say I have a device class and a
calls class. The device here is a telephone handset basically. Telephones
connected to business switchboards can hanlde more than one call at a time -
eg you can have one call on hold while you talk to someone on another call -
there is an active call and a held call.

So is the best bet to have two classes: device class and calls class.
Should calls class inherit from devices class?

No. Asks yourself why you think this might be a good idea. Personally I
can't think of any reason at all why this might be good, but presumable you
are thinking something along the lines of 'if calls inherits from device
then I can do ...'. If so then you are thining wrongly about your design,
you are thinking in terms of you implementation, instead of in terms of what
real world objects you are trying to model.

In C++ public inheritance is used to implement what is confusingly called IS
A relationships, e.g. a secretary is an employee, or a penguin is a bird.
Any other use of public inheritance is fraught with problems.

Sound to me like you need a HAS A relationship. A device has zero or more
calls. Just use ordinary membership for this, e.g.

class Device
{
With telephony much of the activity is generated from the phone. So a phone
could suddenly receive a call. I want to then pass the activity information
to a program using this class. I am a little unsure as to how I get the
call activity information to my program?

For example, my calls class might have a OnIncomingCall function. But how
does my program 'receive' this notification? I can of course have a
OnIncomingCall function in calls class but if I start my telephone program
by calling devices class - how will my calling program know a call has
happened? Or will the Devices class 'have' a OnIncomingCall function
because of the 'child' Calls class function OnIncomingCall.

Not really sure what you are asking here, are we talking about a real world
program connected to real phones, or are we talking about a simulation?

I don't understand this statement 'I want to then pass the activity
information to a program using this class' or this 'how will my calling
program know a call has happened?'. In standard C++ there's only one way to
do this, one function must call another. Is there some reason you think this
doesn't work for you?

john
 
N

Nick Hounsome

Angus Comber said:
Hello

I am attempting to build a set of classes which handle telephony. Basically
the handling of phone calls.

My design currently has two main classes - one dealing with the device and
the other with actual calls. So you could say I have a device class and a
calls class. The device here is a telephone handset basically. Telephones
connected to business switchboards can hanlde more than one call at a time -
eg you can have one call on hold while you talk to someone on another call -
there is an active call and a held call.

So is the best bet to have two classes: device class and calls class.

I think you will need rather more than that.
Telephony is surprisingly complicated and there are several ways of
modelling it.
Check out ATAPI and JTAPI for some ideas.
Should calls class inherit from devices class?

Definitely not. Can you say "A call IS-A device"? I think not.
With telephony much of the activity is generated from the phone. So a phone
could suddenly receive a call. I want to then pass the activity information
to a program using this class. I am a little unsure as to how I get the
call activity information to my program?

For example, my calls class might have a OnIncomingCall function. But how
does my program 'receive' this notification? I can of course have a
OnIncomingCall function in calls class but if I start my telephone program
by calling devices class - how will my calling program know a call has
happened? Or will the Devices class 'have' a OnIncomingCall function
because of the 'child' Calls class function OnIncomingCall.

I realise this is all probably very basic. But would really appreciate some
guidance.

You are in way over your depth.
If this is just a learning project I suggest that you try something simpler
to start.
 

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

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top