Guest User

Untitled

a guest
Nov 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /***********************************************************************
  2. Item01 장점2> 객체를 호출 할 때마다 매번 새로운 객체를 생성할 필요는 없다.
  3. ***********************************************************************/
  4. public class Drill {
  5.  
  6. private static final Drill GOOD_ID = new Drill.withId("minikuma");
  7. private static final Drill GOOD_NUM = new Drill.withNum(100);
  8.  
  9. private String id;
  10. private int num;
  11.  
  12. public Drill() { }
  13.  
  14. public Drill(String id) {
  15. this.id = id;
  16. }
  17. public Drill(int num) {
  18. this.num = num;
  19. }
  20. public static Drill withId(String id) {
  21. return new Drill(id);
  22. }
  23. public static Drill withNum(int num) {
  24. return new Drill(num);
  25. }
  26. //client 소스에서 사용
  27. public static void main(String[] args) {
  28. //미리 생성된 객체를 재 사용
  29. Drill drill = GOOD_ID;
  30. Drill numdrill = GOOD_NUM;
  31. }
  32. }
Add Comment
Please, Sign In to add comment