By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

Design question - static list in class

P: n/a
Hi all

I have a design which models a telephone system. Roughly the design has
these two items:

device class which models an extension on the telephone system. The device
constructor takes a extension number. So program starts by creating a
device object for each extension on the telephone system.

Each device object contains a static list of calls. Calls are modelled by a
class object. The class object takes an extension number in its destructor.

There are various find functions to find a call on a device. Usually on a
device there will be 0, 1 or 2 calls.

The list of calls in the device object is static because sometimes a device
object is created on the stack simply to find a call on the device and maybe
report on its status. If the call list were NOT static then I would get a
zero size call list each time I created the device object on the stack. Not
what I want.

I also have a device list - there is only ever one instance of the class
which accesses the device list. So the number of items in the device list
(a std::list) is set after the program starts.

Eg I get hold of the correct device object like this (device is the
extension object);

device* pDev=FindDeviceByDN(dn);

FindDeviceByDN retrieves a copy of the relevant device object in the device
list.

Then I might do something like this:
call* pCall=pDev->GetCallbyCallID(callid);
I am concerned that the static call list might be bad design. But not sure?
What do people think? Does this design seem ok? Anyone see a better
design?

Angus

Oct 11 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Angus" <no****@gmail.comkirjutas:
I have a design which models a telephone system. Roughly the design
has these two items:

device class which models an extension on the telephone system. The
device constructor takes a extension number. So program starts by
creating a device object for each extension on the telephone system.

Each device object contains a static list of calls.
If the "static list" means static data in the C++ sense, then no, each
device object does not contain a list of calls; all device objects are
rather sharing a single list.

Calls are
modelled by a class object.
Sorry, cannot grok this...
The class object takes an extension
number in its destructor.
neither this...

I believe you should better post some sketch in C++ to get some useful
answers.

In general, static data is bad for reentrant code and for multithreading.
It should be used only if all running threads must see and/or alter the
same data state (with proper synchronization, of course). And if your
software is not using multithreading yet, the chances are good IMO that
it might to start to do that in a couple of years, just to make some use
of the multitude of cpu cores the new processors are sporting.

All the best
Paavo
Oct 14 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.