473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.setSwitch(BoolSwitch("v", "verbose", &bVerbose));
parser.setSwitch(GeometrySwitch("s", "size", &sizeGeometry));

// template method
parser.setSwitch(Switch<bool>("v", "verbose", &bVerbose));
parser.setSwitch(Switch<Geometry>("s", "size", &sizeGeometry));

call:
char **argv = {"./example", "--verbose", "-s", "800x600"};
parser.parseCommandLine(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)

Jul 22 '05 #1
1 1619
Markus Seeger wrote:
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?


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)
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gert Van den Eynde | last post by:
Hi all, I have a question on interface design: I have a set of objects that are interlinked in the real world: object of class A needs for example for the operator() an object of class B. On...
2
by: Tony Johansson | last post by:
Hello Experts!! Here we use multiple inheritance from two classes.We have a class named Person at the very top and below this class we have a Student class and an Employee class at the same...
0
by: JKJ | last post by:
I'm not an OOP guru, but I would say ". . .not necessarily" What if the base class and derived classes are internal? Then the base class has to be within the same assembly to be inherited from. ...
4
by: Gibby Koldenhof | last post by:
Hiya, I'm setting up some code in the spirit of Design Patterns, OOP, etc. All nice and well, it handles pretty much all OO style things and serves my purposes well. There's one last final...
6
by: Mr.Tickle | last post by:
How can I impleement a singleton pattern in an abstract or interface for inheritance to an object so all the pattern rules are followed on all similar objects?
11
by: Peter Oliphant | last post by:
Is there any plan to support templates with managed code in the (near) future? For instance, VS.NET 2005... : )
1
by: Joe Hughes | last post by:
Hi All I'm a seasoned ASP programmer and have been writing ASP for years. I've decided now to stop writing ASP and jump onboard the ASP.NET bandwagon (albeit a bit late). I've been...
4
by: srinivasarao_moturu | last post by:
class ABC { public : virtual void operation1(); virtual void operation2(); virtual int GetValue(); virtual char GetValue(); virtual void SetValue(int); virtual void SetValue(char); }
5
by: Nitesh | last post by:
Objects of type X are basic building blocks of my application and there are a few functions which return XHandle (typedef X** XHandle). The task at hand needs to use a couple of these functions and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.