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: Bharathi Thiyagarajan <bharathi.thiyagarajan AT adcc.alcatel.be>
  • From: Thiyagarajan_BHARATHI/IN/ALCATEL@ALCATEL
  • To: Prabodh Saha <prabodhs AT ivycomptech.com>
  • Cc: 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 14:36:50 +0530
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>
  • Organization: Alcatel Development Center Chennai

Thanks for you suggestion

It would be really nice if we could discuss for this scenario, the design
pattern
cannot be
state for the following points and it cannot be a template for the following
points.
so that we can
come to a conclusion. we can also discuss for this scenario, in such a
situation it
can be designed
as a template method or state. Please give your valuable suggestions.


The class diagram that I drew was not aligned properly

Here is the code skeleton:

class TraceParser
{ public:
virtual void parserTrace();
}

class AParserType : public TraceParser
{ public:
parserTrace() { cout << "A Parser Type"; }
}

class BParserType : public TraceParser
{ public:
parserTrace() { cout << "B Parser Type"; }
}

class CParserType : public TraceParser
{ public:
parserTrace() { cout << "C Parser Type"; }
}

class Trace
{ public:
Trace(TraceType)
{ if TraceType == A /* TraceType is an enum. */
TraceParserObject = new AParserType()
else if TraceType == B
TraceParser Object = new BParserType()
else if TraceType == C
TraceParserObject = new CParserType()
else
...return error
TraceParserObject->parseTrace();
}

private :
TraceParser *TraceParserObject;
}

In my Main Object:
Trace *TraceFile = new Trace(checkTraceType());


It would be really nice if we could discuss for this scenario, the design
pattern
cannot be
state for the following points and it cannot be a template for the following
points.
so that we can
come to a conclusion. we can also discuss for this scenario, in such a
situation it
can be designed
as a template method or state. Please give your valuable suggestions.

Thanks and Regards
Bharathi




Prabodh Saha wrote:

> 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