Design question - static list in class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angus

    #1

    Design question - static list in class

    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=FindDevice ByDN(dn);

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

    Then I might do something like this:
    call* pCall=pDev->GetCallbyCallI D(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



  • Paavo Helde

    #2
    Re: Design question - static list in class

    "Angus" <nospam@gmail.c omkirjutas:
    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

    Comment

    Working...