Skip to Content.
Sympa Menu

gang-of-4-patterns - RE: [gang-of-4-patterns] strategy, state , template ????

gang-of-4-patterns AT lists.cs.illinois.edu

Subject: Design Patterns discussion

List archive

RE: [gang-of-4-patterns] strategy, state , template ????


Chronological Thread 
  • From: "Prabodh Saha" <prabodhs AT ivycomptech.com>
  • To: "Bharathi Thiyagarajan" <bharathi.thiyagarajan AT adcc.alcatel.be>, "gag-of-4-patterns" <gang-of-4-patterns AT cs.uiuc.edu>
  • Subject: RE: [gang-of-4-patterns] strategy, state , template ????
  • Date: Fri, 19 Dec 2003 13:52:04 +0530
  • Importance: Normal
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

Bharathi,
I think u should use the strategy pattern here,
'cause the requirement specs of your problem warrants so.

Define an abstract class Trace
(with all the functions common to A,B,C parserType) and just
the declaration of functions that will have different
implementations for A,B and C.

Now you have a ParserObject (that holds a reference to Trace)
and has a public method parserObject.setParser(Trace trace).
Make this ParserObject a memeber of your Main object.

Your Main object will decide the file type to be parsed.
Say it decides it is of type A.
Then call: parserObject.setParser(new AparserType);
Then call parserObject.method1()
.method2()
etc.
from your main object.
[NOTE: these method1(), method2() etc. of parserObject will
internally call
the public methods you declared in your abstract class "Trace" and
defined
(some of them) differently in different types of Parsers.]

Once done with the 1st file, your Main object can pickup another file.
Decide its type (say TypeB now) and configure its parserObject with
"new BparserType()" and the rest is same.


Regards,
Prabodh



-----Original Message-----
From:
gang-of-4-patterns-admin AT cs.uiuc.edu
[mailto:gang-of-4-patterns-admin AT cs.uiuc.edu]On
Behalf Of Bharathi
Thiyagarajan
Sent: Friday, December 19, 2003 10:38 AM
To: gag-of-4-patterns
Subject: [gang-of-4-patterns] strategy, state , template ????


Hello *

I think I will give a glimpse of scenario of my problem so that
we can discuss and conclude which will be the best design pattern

Here is the scenario:
I have 3 types of trace files (A , B, C) each has
its own format and requires a different way of parsing the file to pick
data from the file.
so Afile has a Aparser, Bfile has Bparser, and
Cfile has Cparser. apart from these Aparser, Bparser, Cparser there are
common methods
that can be reused for parsing the file.

Now the design for this:

Trace <>--------> TraceParser

/ | \ (sorry the lines
here indicate inheritance/generalization)

AparserType BparserType CparserType

Points for discussion:
1. If TraceParse has a method ParserTrace which
AparseType , BparseType , CparserType has different implementation for
it --- It is Strategy
2. If TraceParser has many methods some of them are
common for the three parser types and some of then have been overridden
by the three parser Types -
is it a template method ????
3. The input file at a point can be one of TraceType,
Trace will decided by checking the file which TraceType is it and based
on that object AparserType/
BparserType/CparserType is created

Please enlighten me , correct me so that I will learn from my
mistakes.

Thanks & Regards
Bharathi






_______________________________________________
gang-of-4-patterns mailing list
gang-of-4-patterns AT cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/gang-of-4-patterns





Archive powered by MHonArc 2.6.16.

Top of Page