-
as seen on Stack Overflow
- Search for 'Stack Overflow'
Motivation
Recently I searched for a way to initialize a complex object without passing a lot of parameter to the constructor. I tried it with the builder pattern, but I don't like the fact, that I'm not able to check at compile time if I really set all needed values.
Traditional builder pattern
When…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
In a legacy codebase I have a very large class with far too many fields/responsibilities. Imagine this is a Pizza object.
It has highly granular fields like:
hasPepperoni
hasSausage
hasBellPeppers
I know that when these three fields are true, we have a Supreme pizza. However, this class is not…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
Hi all,
I'm attempting to create a class with many parameters, using a Builder pattern rather than telescoping constructors. I'm doing this in the way described by Joshua Bloch's Effective Java, having private constructor on the enclosing class, and a public static Builder class. The Builder class…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
Does anyone have any links to some code they like that shows a good example of this in c#?
As an example of bad code, here is what a builder I have now looks like. I'm trying to have a way to keep the flexibility of the builder pattern but not rebuild the properties.
Cheers,
Berryl
public abstract…
>>> More
-
as seen on Stack Overflow
- Search for 'Stack Overflow'
I'd like Jackson to deserialize a class with the following constructor:
public Clinic(String name, Address address)
Deserializing the first argument is easy. The problem is that Address is defined as:
public class Address
{
private Address(Map<LocationType, String> components)
...
…
>>> More