Brainiacs: Methodology to choose best of many class to handle abstract data

A

arieljake

I am creating a program that will be handling files from potentially
numerous sources. I will be extending a base Parser class for each
possible source of data to extract data in a manner specific to the
format of the File. Along with a parse(File) function, the Parser
objects will also have a canParse(File) function.

What I am looking for is to build a framework that will allow me to
update the overall program by adding new sub-classes of Parser with
ease. The Parser objects once created will not change much. Just the
number of Parser object to be considered for parsing data.

How can I "register" these Parser modules so that the appropriate
Parser class can be requested to parse my data?

Possible options I have thought of: a database with fields to be
queried, a properties file, neural networks (though I don't know how
yet), or simply a ton of if/else statements.

Given certain characteristics and "header" attributes of the File, how
can I efficiently determine the best Parser class to handle my data?

thank you,

Ariel
 
T

toxa26

Look into Factory or Abstract Factory design pattern. Google around
for "Gang of four" or design pattern in general. There is a large
number of creation patterns that people use for these situations.
 
A

arieljake

Thank you very much for the direction. For those that find this article
in the future, here is an indication of how perfect of a solution the
"Factory design Pattern" is for this question:

The Problem
One of the goals of object-oriented design is to delegate
responsibility among different objects. This kind of partitioning is
good since it encourages Encapsulation and Delegation.

Sometimes, an Application (or framework) at runtime, cannot anticipate
the class of object that it must create. The Application (or framework)
may know that it has to instantiate classes, but it may only know about
abstract classes (or interfaces), which it cannot instantiate. Thus the
Application class may only know when it has to instantiate a new Object
of a class, not what kind of subclass to create.
a class may want it's subclasses to specify the objects to be created.
a class may delegate responsibility to one of several helper subclasses
so that knowledge can be localized to specific helper subclasses.

The Solution
Factory Method...
 
A

arieljake

Thank you very much for the direction. For those that find this article
in the future, here is an indication of how perfect of a solution the
"Factory design Pattern" is for this question:

The Problem
One of the goals of object-oriented design is to delegate
responsibility among different objects. This kind of partitioning is
good since it encourages Encapsulation and Delegation.

Sometimes, an Application (or framework) at runtime, cannot anticipate
the class of object that it must create. The Application (or framework)
may know that it has to instantiate classes, but it may only know about
abstract classes (or interfaces), which it cannot instantiate. Thus the
Application class may only know when it has to instantiate a new Object
of a class, not what kind of subclass to create.
a class may want it's subclasses to specify the objects to be created.
a class may delegate responsibility to one of several helper subclasses
so that knowledge can be localized to specific helper subclasses.

The Solution
Factory Method...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top