wood burning stoves*
The moose likes Beginning Java and the fly likes Factory Class?? 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 » Java » Beginning Java
Bookmark "Factory Class??" Watch "Factory Class??" New topic
Author

Factory Class??

Daniel Sie
Greenhorn

Joined: Aug 13, 2001
Posts: 7
I've heard of factory methods. But what is a factory class?
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

I'm not sure either but would it be a class that is instantiated only via its factory method(s) ?
Pho


Regards,

Pho
John Warland
Greenhorn

Joined: Jul 11, 2001
Posts: 3
The idea of a factory class is that it is a class which will create an object for you when you request one.
They are most useful when you want to create lots of similar objects.
so for example, normally you would type
myObject1 = new Object(10, 1);
myObject2 = new Object(10, 2);
myObject3 = new Object(10, 3);
to create series of objects which are similar.
Instead you could just call a method in your factory class like:
myObject1 = myFactClass.giveMeAnother(1);
myObject2 = myFactClass.giveMeAnother(2);
and method giveMeAnother would be something like
public Object giveMeAnother(int val) {
Object newObject = new Object(10, val);
return newObject;
}
Basically the idea is to give you more control over the creation of your objects. So for example if you wanted to change the default value 10 to something else then you would only have to do it in one place.
Daniel Sie
Greenhorn

Joined: Aug 13, 2001
Posts: 7
Thanks John!!! It looks similar to an Array List to me.
 
 
subject: Factory Class??
 
Similar Threads
WA #1.....word association
Jar File, Design.txt
What is a factory class?
Factory classes??
Factory class