Skip to content

Instantly share code, notes, and snippets.

@minikuma
Created November 19, 2018 01:34
Show Gist options
  • Select an option

  • Save minikuma/d6fe0a5c7940663776bbe5fd410c8c83 to your computer and use it in GitHub Desktop.

Select an option

Save minikuma/d6fe0a5c7940663776bbe5fd410c8c83 to your computer and use it in GitHub Desktop.
/***********************************************************************
Item01 장점2> 객체를 호출 할 때마다 매번 새로운 객체를 생성할 필요는 없다.
***********************************************************************/
public class Drill {
private static final Drill GOOD_ID = new Drill.withId("minikuma");
private static final Drill GOOD_NUM = new Drill.withNum(100);
private String id;
private int num;
public Drill() { }
public Drill(String id) {
this.id = id;
}
public Drill(int num) {
this.num = num;
}
public static Drill withId(String id) {
return new Drill(id);
}
public static Drill withNum(int num) {
return new Drill(num);
}
//client 소스에서 사용
public static void main(String[] args) {
//미리 생성된 객체를 재 사용
Drill drill = GOOD_ID;
Drill numdrill = GOOD_NUM;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment