dynamic polymorphism or std::list<boost::any>

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

    dynamic polymorphism or std::list<boost::any>

    Hi,

    I am thinking now for a while about a design decision. I would be glad if
    you can give me some advices which is maybe the better way for solving my
    problem.
    I wanna do something like described in the Bridge-Pattern. Therefore I have
    the following classes:
    Instrument
    InstrumentImpl
    InstrumentData
    An Instrument has an InstrumentImpl ( for example how to make an instrument
    viewable ) and an InstrumentData ( holds the data of the instrument, for
    example in a map, or often other structures and can perform special
    operations on it, like calculating the max of all data in the map ).
    Furhtermore there is a class Panel which holds all Instruments in a
    std::list. My question is now what you think is the better approach for
    solving this design problem:
    1.) Using dynamic-polymorphism with common base-classes for Instrument,
    InstrumentImpl and InstrumentData and connect a specific InstrumentImpl and
    InstrumentData object with an Instrument object by using the ctor
    Instrument(Base _InstrumentImpl * imp, Base_Instrument Data* data). And then
    using in the Panel-class a std::list<Instr ument*>.
    2.) Using templates the way that Instument is a class template:
    template<typena me impl, typename data> class Instrument and then using in
    the Panel class a std::list<boost ::any>.
    The important thing is that in general it would be hard for me to find a
    common base-class for the data- and impl-classes. So it would be better if
    the data- and impl-types would be unrelated. That's why IMHO I tend to use
    the second solution.

    Thanks in advance,
    Sebastian



Working...