• 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

Factory Design-Pattern: (PDFFactory) can you access the db in the getPDF?

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

I have PDFFactory where given a type of EMPLOYEE I construct a pdf.
the code looks like this:



So...it appears that the information in the SysArchitectPDF is insufficient! I need to access the DB to get more info (all projects the sys architect has worked on). I wonder if doing this:



will not destroy my design. Meaning, is there a better way to do this? I don't want to fetch the information from within the SysArchitectPDF but I need to get it somewhere.

Thanks for any pointers.

 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The purpose of your factory object is to create PDF objects, that is all it should do.

The activities of looking up data in a database should not be handled by the factory object for creating PDF objects.

Don't forget that there is a client object that is using the factory object, so whatever other operations are needed, e.g. populating
the data fields of a PDF Object, then the client object is most likely where this code belongs, or somewhere else in the application.





One method = one return statement leads to cleaner, understandable code...
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Pinkerton wrote:
One method = one return statement leads to cleaner, understandable code...



That's debatable.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the sequence diagram of the code of Adrian Burlington
sequence_diagram_adrian_burlington_code.png
[Thumbnail for sequence_diagram_adrian_burlington_code.png]
 
Vlad Varnica
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the reverse communication and sequence diagram of the code of Henry Pinkerton
pinkerton_code_sequence_diagram.png
[Thumbnail for pinkerton_code_sequence_diagram.png]
pinkerton_code_communication_diagram.png
[Thumbnail for pinkerton_code_communication_diagram.png]
 
Adrian Burlington
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your input. Yes, I agree it should not be in the Factory.

Also, nice diagrams Vald, can you tell us how you did that?

Thanks!
 
Vlad Varnica
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use Eclipse 3.5 SR2 and have copied your code in a new project. I then reverse it with an Eclipse modeling tool.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic