Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Creating funny objects
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Paul Tomblin, post: 592670"] In a previous article, [email]hopkins81@gmail.com[/email] (hopkins) said: There is a book called "Design Patterns" which explains all this. You should get it. Basically, a "factory" is used so that the programmer can override it to create a (or more than one different) subclass of SAXParser. If I have a class called "fooParser" and another class called "barParser", both of which are subclasses of SAXParser, I only have to make the factory return fooParsers or barParsers as the circumstances may merit, instead of SAXParsers, and all the other code stays the same. The factory method "newInstance" would do the appropriate "new fooParser" or "new barParser" inside it. For instance, in the application I'm working on right now, I have a class called "Playlist". I have subclasses called "AdvertisingPlaylist", "FeaturePlaylist", "TrailerPlaylist" and "SnipePlaylist". "FeaturePlaylist" has two subclasses "FilmPlaylist" and "DigitalFeaturePlaylist". I have a PlaylistFactory with a method "newPlaylist(int type)", which does a Playlist n = null; switch(type) { case TYPE_ADVERTISING: n = new AdvertisingPlaylist(); break; case TYPE_TRAILER: n = new TrailerPlaylist(); break; ... } return n; And so where-ever I need a new Playlist, I call on the factory to make it rather than having that switch statement in each place. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Creating funny objects
Top