mirror of
https://github.com/sjsdfg/effective-java-3rd-chinese.git
synced 2025-01-26 20:30:36 +08:00
update
This commit is contained in:
parent
402b216416
commit
157dde3c48
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user