This commit is contained in:
sjsdfg 2019-06-05 23:33:29 +08:00
parent 402b216416
commit 157dde3c48

View File

@ -7,7 +7,6 @@
```java
// Telescoping constructor pattern - does not scale well!
public class NutritionFacts {
private final int servingSize; // (mL) required
private final int servings; // (per container) required
@ -61,7 +60,6 @@ NutritionFacts cocaCola = new NutritionFacts(240, 8, 100, 0, 35, 27);
```java
// JavaBeans Pattern - allows inconsistency, mandates mutability
public class NutritionFacts {
// Parameters initialized to default values (if any)
private int servingSize = -1; // Required; no default value
@ -102,7 +100,6 @@ cocaCola.setCarbohydrate(27);
```java
// Builder Pattern
public class NutritionFacts {
private final int servingSize;
private final int servings;
@ -178,7 +175,6 @@ NutritionFacts cocaCola = new NutritionFacts.Builder(240, 8)
```java
// Builder pattern for class hierarchies
import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;