Re: a question about factory method
On 18.12.2014 20:24, Eric Sosman wrote:
As to *how* a factory method might choose which of several classes
to return, you already illustrated one way (paraphrased):
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;
}
}
To me, this doesn't seem a huge advantage: The caller who writes
`getInstance(date, 2)' could just as easily write `new MayanCalendar()'
with about the same effect.
The crucial point is that the caller does not need to know the criteria
when to create what type. That _is_ a huge advantage.
Cheers
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/