Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using a Factory Pattern in a Web Based Application

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put your code in web-base application .
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , its a silly doubt .THanks
 
Angus Edison
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic