This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Adrian Burlington
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Pinkerton wrote:
One method = one return statement leads to cleaner, understandable code...


That's debatable.
 
Vlad Varnica
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic