File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Design Patterns Factory Method example" Watch "Design Patterns Factory Method example" New topic
Author

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.
Thanks
John Wetherbie
Rancher

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.
John


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