A
alebcn75
Hello,
I'm trying to solve the following issue which is puzzling me.
I have a concrete class, say Parser, which provides some basic parsing
functionality (such as reading word by word, line by line, etc)
Then I have a second Parser-derived class, say HtmlParser, which
besides providing the Parser functionality, provides extra features,
such as read tag by tag, attributes, etc..
What I'd like to achieve is a "factory" which would return the proper
class depending on the content type received, so I'd call this factory
like factory.create("html");, etc
The problem I'm facing is that the derived parser will contain more
methods which are not available in the base class.
So how can I achieve a generic behavior without relying on if/else/
switch constructs? So far the only way I see is dynamic casting the
Parser pointer returned by the factory, but I feel this defeats the
whole purpose of a factory.
The other obvious approach would be putting all methods in the base
class, but some of them wouldn't have any sense.. such as reading a
tag from a generic text..
Any hint to where I can find some pointers? Thank you.
I'm trying to solve the following issue which is puzzling me.
I have a concrete class, say Parser, which provides some basic parsing
functionality (such as reading word by word, line by line, etc)
Then I have a second Parser-derived class, say HtmlParser, which
besides providing the Parser functionality, provides extra features,
such as read tag by tag, attributes, etc..
What I'd like to achieve is a "factory" which would return the proper
class depending on the content type received, so I'd call this factory
like factory.create("html");, etc
The problem I'm facing is that the derived parser will contain more
methods which are not available in the base class.
So how can I achieve a generic behavior without relying on if/else/
switch constructs? So far the only way I see is dynamic casting the
Parser pointer returned by the factory, but I feel this defeats the
whole purpose of a factory.
The other obvious approach would be putting all methods in the base
class, but some of them wouldn't have any sense.. such as reading a
tag from a generic text..
Any hint to where I can find some pointers? Thank you.