wood burning stoves 2.0*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Design Patterns Factory Method example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Design Patterns Factory Method example" Watch "Design Patterns Factory Method example" New topic

Design Patterns Factory Method example

Madhu Juneja
Ranch Hand

Joined: Mar 10, 2001
Posts: 176
The following is an example of Factory Method :

createDocument() is the factory method and I can have another class MyAnotherDocument2 and then in the MyApplication class create an object of MyAnotherDocument2 and return it.
This is the meaning of the defn :

Factory Method (createDocument() here )defines an interface for creating an object, but let subclasses (MyApplication) decide which class to instantiate.

Please provide comments on my understanding. Thanks
Walter Vetrivel
Ranch Hand

Joined: Mar 01, 2001
Posts: 80
Looks alright to me but I guess u want a further elaboration
on this and so do I, maybe Mr.Wetherbie can comment on this.
John Wetherbie

Joined: Apr 05, 2000
Posts: 1441
The example looks pretty similar to the example they use in the Design Patterns book.
I think your understanding of what is going on is correct. Remember that the alternate name for factory (and the name that I knew it by first) is virtual constructor.
I'm not if what I wote is helpful or not. I'm sure you'll let me know.

The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Madhu Juneja
Ranch Hand

Joined: Mar 10, 2001
Posts: 176
What you write here is always very much helpful. Thanks.
I agree. Here's the link: http://aspose.com/file-tools
subject: Design Patterns Factory Method example
Similar Threads
Dynamic method lookup
Using Struts 2.0.11 Action as Ajax backend
Method-local Inner Class Q
"cannot be applied to" error using XML
Factory Method pattern