Skip to content

Instantly share code, notes, and snippets.

@choiseungho
Created September 21, 2015 04:05
Show Gist options
  • Save choiseungho/3d18c90b3673100e9ff5 to your computer and use it in GitHub Desktop.
Save choiseungho/3d18c90b3673100e9ff5 to your computer and use it in GitHub Desktop.
점층적 생성자 패턴
package com.tistory.seungdols.effetive.ex_1;
/**
* @PROJECT effectiveJava
* @PACKAGE com.tistory.seungdols.effetive.ex_1
* @WRITTER Administrator
* @DATE 2015-09-21
* @HISTORY
* @DISCRIPT
*/
public class NutritionFactsEx1 {
private final int servingSize;
private final int servings;
private final int calories;
private final int fat;
private final int sodium;
private final int carbohydrate;
/*
점층적 생성자 패턴
*/
public NutritionFactsEx1(int servingSize, int servings) {
this(servingSize, servings,0);
}
public NutritionFactsEx1(int servingSize, int servings, int calories) {
this(servingSize, servings, calories,0);
}
public NutritionFactsEx1(int servingSize, int servings, int calories,int fat) {
this(servingSize, servings, calories,fat,0);
}
public NutritionFactsEx1(int servingSize, int servings, int calories,int fat, int sodium) {
this(servingSize, servings, calories,fat,sodium,0);
}
public NutritionFactsEx1(int servingSize, int servings, int calories, int fat, int sodium, int carbohydrate) {
this.servingSize = servingSize;
this.servings = servings;
this.calories = calories;
this.fat = fat;
this.sodium = sodium;
this.carbohydrate = carbohydrate;
}
public int getServingSize() {
return servingSize;
}
public int getServings() {
return servings;
}
public int getCalories() {
return calories;
}
public int getFat() {
return fat;
}
public int getSodium() {
return sodium;
}
public int getCarbohydrate() {
return carbohydrate;
}
public static void main(String[] args) {
NutritionFactsEx1 coca = new NutritionFactsEx1(240,8,100,3,35,27);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment