aspose file tools*
The moose likes Java in General and the fly likes Using a Factory Pattern in a Web Based Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using a Factory Pattern in a Web Based Application" Watch "Using a Factory Pattern in a Web Based Application" New topic
Author

Using a Factory Pattern in a Web Based Application

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Hello,



I had understood what is a Factory Pattern with the above example.
Can anybody please tell , how an Factory Pattern would be useful in a WebBased application .
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
Put your code in web-base application .


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
The only difference between a web based app and an ordinary app is how the user accesses your application.

It has got nothing to do with the way you implement your "business logic". So, well, yeah, like Kenkag mentioned, put your factory pattern in a web application
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Yes , its a silly doubt .THanks
Angus Edison
Greenhorn

Joined: Apr 08, 2009
Posts: 3
I think the question should be changed from "how an Factory Pattern would be useful in a WebBased application" to "why or when we need to use Factory Pattern". The beauty of the Factory Pattern is you can "inject" new implementation to your system without large scale change. Factory Pattern encapsulate (or hide away) the creation of the real instance. That means, if you need to provide different sub-class of the class or interface, you don't need to change large segment of code.

As your example, if you need to introduce new kind of Person (e.g. ET), you just need to change one place (the "getDetails(..) function).
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using a Factory Pattern in a Web Based Application