*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Factory Design-Pattern: (PDFFactory) can you access the db in the getPDF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Factory Design-Pattern: (PDFFactory) can you access the db in the getPDF?" Watch "Factory Design-Pattern: (PDFFactory) can you access the db in the getPDF?" New topic
Author

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

Adrian Burlington
Ranch Hand

Joined: Jun 16, 2009
Posts: 75
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

Joined: Apr 16, 2008
Posts: 2187
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

Joined: Mar 10, 2008
Posts: 1761
    
    7

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


That's debatable.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Vlad Varnica
Ranch Hand

Joined: Dec 28, 2002
Posts: 40
Here is the sequence diagram of the code of Adrian Burlington


[Thumbnail for sequence_diagram_adrian_burlington_code.png]

Vlad Varnica
Ranch Hand

Joined: Dec 28, 2002
Posts: 40
Here is the reverse communication and sequence diagram of the code of Henry Pinkerton


[Thumbnail for pinkerton_code_sequence_diagram.png]

[Thumbnail for pinkerton_code_communication_diagram.png]

Adrian Burlington
Ranch Hand

Joined: Jun 16, 2009
Posts: 75
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

Joined: Dec 28, 2002
Posts: 40
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
 
subject: Factory Design-Pattern: (PDFFactory) can you access the db in the getPDF?