• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Desing issue, may be with Visitor pattern

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I have got a design issue.
I am Developing application for "application log" - which will be transformed into web reports or will be stored into Database.

Report is an interface.
- boolean validateLogStatement(String statement)
- addLogStatement(String statement)
- setWriter(ReportWriter writer)

ReportExecutor will get a file and a Report reference as a constructor parameter. and execute line by line on Report.

it must be clear that i'll be having different implementation Report classes.
i.e. PingLogReport

these implementation report class is implementing visitor pattern. So they have visit method.

& i am having different visitor interfaces for different implementation report classes, i.e. PingReportVisitor and it's implementation visitor classes i.e. PingReportSummaryVisitor.

Now, is there anyway i can generalized(declare) this visitors into Report interface, (Abstract class can also work, i don't have any problem).???

I did it, but i have to cast it into Visitor implementation. Which i don't want to do.

And please comment on design also.

Regards,
Nachiket
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you take a look at the Visitor pattern yet? It sounds like it's not what you currently have, and might be what you actually want to have.
 
Nachiket Patel
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ilja,

Did you take a look at the Visitor pattern yet? It sounds like it's not what you currently have, and might be what you actually want to have.


Yeah, i looked at it, created one example first.

On problem i found is,
Method in Report classes class should be accept(Visitor visitor);

I found one more problem that i was trying to implement "dual dispatch" Visitor. And in dual dispatch, you have to provider list of visit() method in Visitor, like visit(LogReport report), visit(XYZReport report) etc.

Other then this, please tell me, why you feel it is not implementing visitor??
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Visitor pattern is all about dual dispatch. It sounded to me like that's not what your design is using - otherwise, you wouldn't have a "visitor" interface per report class, for example. Did I misunderstand?
 
Nachiket Patel
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, you are right,
i think Visitor interface (ReportVisitor) will have
visit(PingLog log),
visit(TransactionLog log)....

and, if new report comes up, i have to add one more method in visitor interface and it's implementing concrete visitor classes. Right??

actually got confused,
Because i do not need all the visitor for all the logs. Like TransactionLog is not having need of Summary Report. But i have to implement method in concrete visitor implementations .
[i.e SummaryLogVisitor will have method like visit(TransactionLog log); ]

Is there a work around??

-Nachiket
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds to me that the Visitor pattern might not be a good fit for your problem - it works best when the class hierarchy is relatively fixed and only the operations are in flux - so that the Visitor interface can be stable.

Perhaps would benefit from a more dynamic approach. Like registries where you can register commands for reports or something...
 
Nachiket Patel
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ilja,

i convinced my manager, for using JasperReports instead of making manual HTML reports.

So no manual reporting application is needed.


Anyways, Thanks for helping.

-Nachiket
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic