Created
November 19, 2018 01:34
-
-
Save minikuma/d6fe0a5c7940663776bbe5fd410c8c83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*********************************************************************** | |
| 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