design question: templates or inheritance?

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

    design question: templates or inheritance?


    Hi,

    I'm writing a commandline argument parser that can handle switches
    by using some techniques similar to the Qt slot mechanism.

    example:
    // inheritance method (what I'm trying at the moment)
    parser.setSwitc h(BoolSwitch("v ", "verbose", &bVerbose));
    parser.setSwitc h(GeometrySwitc h("s", "size", &sizeGeometry)) ;

    // template method
    parser.setSwitc h(Switch<bool>( "v", "verbose", &bVerbose));
    parser.setSwitc h(Switch<Geomet ry>("s", "size", &sizeGeometry)) ;

    call:
    char **argv = {"./example", "--verbose", "-s", "800x600"};
    parser.parseCom mandLine(4, argv);

    Internally I store the Switches in a map using Switch * base pointers.
    The appropriate method is called later using dynamic binding.

    Q:
    So if I'm going to use templates, can I create a similar anonymous
    Switch * array? I can't use Switch<someType > * because I don't know
    the specific type at definition time...

    Somehow templates seem more elegant to use here. Perhaps it's just
    my urge to finally start using templates somewhere ;)

    Q:
    In the case of non-atomic types like Geometry (2 params), I am in
    need of a generic parse method... using inheritance it's just overriding,
    but what to do with templates? Is this a k.o.-criteria for templates?

    thx in advance, Markus

    --
    Analysis: sums with letters. It's for the people whose
    brains aren't clever enough for numbers. (Terry Prattchet)

  • Markus Seeger

    #2
    Re: design question: templates or inheritance?

    Markus Seeger wrote:
    [color=blue]
    > Q:
    > In the case of non-atomic types like Geometry (2 params), I am in
    > need of a generic parse method... using inheritance it's just overriding,
    > but what to do with templates? Is this a k.o.-criteria for templates?[/color]

    If this second one is a pattern question and doesn't belong here, just
    ignore it ;D

    --
    Analysis: sums with letters. It's for the people whose
    brains aren't clever enough for numbers. (Terry Prattchet)

    Comment

    Working...