This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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: 1449
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:
subject: Design Patterns Factory Method example
It's not a secret anymore!