Timeline for answer to Managing constructors with many parameters in Java by Eli Courtwright
Current License: CC BY-SA 3.0
Post Revisions
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 20, 2024 at 1:31 | comment | added | veritas | Is this example trying to say that no inheritance chain may be required if we could put all the paramters of the chain of classes into into one class and just create a builder with some fields being optional and others throwing exception if missing? | |
| Apr 6, 2018 at 6:53 | review | Suggested edits | |||
| Apr 6, 2018 at 7:55 | |||||
| Oct 7, 2016 at 19:59 | comment | added | user3437460 | I would say, this is a nice solution | |
| S Jul 14, 2015 at 8:04 | history | suggested | Dennis Christian | CC BY-SA 3.0 |
Clarified, removed redundancy.
|
| Jul 14, 2015 at 7:32 | review | Suggested edits | |||
| S Jul 14, 2015 at 8:04 | |||||
| Nov 13, 2014 at 12:25 | comment | added | WVrock |
@EliCourtwright I guess it is about preference/code design. Instead of making the constructor throw the exception I made the buildStudent() method throw the exception.
|
|
| Nov 12, 2014 at 15:07 | comment | added | Eli Courtwright | @WVrock: It depends on your implementation. As I say in my answer, doing this with the student class itself could potentially leave the class in a half-initialized state, e.g. if you have a required field which has not yet been initialized. | |
| Nov 10, 2014 at 22:39 | comment | added | WVrock | Technically speaking, it is possible to use Student class to build a new student. I've added the methods inside the Student class and it worked just fine. This way I didn't need to have another builder class. I'm not sure if this is desirable though. Is there a reason to use another(StudentBuilder) class to build it? | |
| Apr 10, 2013 at 14:12 | history | edited | Eli Courtwright | CC BY-SA 3.0 |
fixed typo
|
| Feb 16, 2012 at 15:46 | comment | added | user443854 | @oxbow_lakes: In your example, which class has static method name(String name)? | |
| Oct 21, 2008 at 20:46 | comment | added | oxbow_lakes | Of course with static imports you never even have to "see" these "builders" at all. For example, you could have static methods name(String name) which returns a builder and Student(StudentBuilder) which returns a student. Hence Student(name("Joe").age(15).motto("I've wet myself")); | |
| Oct 21, 2008 at 20:07 | vote | accept | Steve Armstrong | ||
| Oct 21, 2008 at 15:27 | history | answered | Eli Courtwright | CC BY-SA 2.5 |