|
|
|
|
|
by Someone
4769 days ago
|
|
Method cascades do not guarantee that the object gets properly initialized. Let's say you do var calendar = new Calendar()
..year = 2013
..date = 6;
Neither the year setter nor the day setter can throw, as they cannot know that there is no month setter in your code.So, what month is the date set to after that code? Builder.build(), on the other hand, can throw when called on a partly initialized builder. A builder also can (I don't know whether Java's builder do this) accept variants such as: Builder.setYear(2012).setDay(60); // February 29
Builder.setYear(2000).setDay(MONDAY).setWeek(14);
// Monday of week 14 of week 2000
So, builders have their advantages. |
|