• Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,363
On Slideshare
0
From Embeds
0
Number of Embeds
5

Actions

Shares
Downloads
44
Comments
0
Likes
10

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. PL
  • 2.   in
  • 3.   Java
  • 4.   
  • 5.    Week02
  • 6.    Object & Class 조영호
  • 7.    snatcher@nhn.com
  • 8.   
  • 9. G o a l 
  • 10.    O O 패 러 다 임 
  • 11.    이 해 
  • 12.    설 명 만 
  • 13.    많 고 
  • 14.    코 드 는 
  • 15.    별 로 
  • 16.    없 어 요 
  • 17.   
  • 18. Conceptual Perspective
  • 19.    Implementation Perspective
  • 20.    객체지향
  • 21.    Object-Orientation
  • 22.    개념
  • 23.   관점
  • 24.    구현
  • 25.   관점
  • 26.   
  • 27. Conceptual Perspective
  • 28.    Implementation Perspective
  • 29.    객체지향
  • 30.    Object-Orientation
  • 31.    개념
  • 32.   관점
  • 33.    구현
  • 34.   관점
  • 35.    Object & Collaboration
  • 36.    Object-Oriented Programming Language
  • 37.   
  • 38. To p i c s 
  • 39.    Conceptual Perspective Implementation Perspective Object & Class
  • 40. OO == 실세계의
  • 41.   모방?
  • 42.    실무
  • 43.   관점에서는
  • 44.   부적절하지만
  • 45.    개념을
  • 46.   이해하는
  • 47.   데는
  • 48.   유용함
  • 49.   
  • 50. Object-Orientation
  • 51.    http://www.slideshare.net/baejjae93/roles- responsibilities-collaborations
  • 52. Object Object Object 협력
  • 53.   
  • 54. message Object Object Object Object 협력에
  • 55.   참여하는
  • 56.   객체
  • 57.   
  • 58. message Object 메시지를
  • 59.   처리하기
  • 60.   위한
  • 61.   행동
  • 62.    Behavior Object Object Object
  • 63. message Object behavior 행동에
  • 64.   필요한
  • 65.   상태
  • 66.    State Object Object Object
  • 67. OO Design
  • 68.    message? message State
  • 69.   Behavior
  • 70.    state?
  • 71. State?
  • 72.    plusOne ?
  • 73. State?
  • 74.    plusOne plusOne minusOne setZero plusOne setZero 2
  • 75. State?
  • 76.    plusOne 1
  • 77. State?
  • 78.    2
  • 79. plusOne 1 2 5 plusOne plusOne Dynamic
  • 80.   
  • 81. plusOne plusOne plusOne Dynamic
  • 82.    2 3 6
  • 83. plusOne plusOne plusOne Dynamic
  • 84.    2 3 6 Complex!
  • 85.   
  • 86. Static
  • 87.    2 3 6 1 2 5 Number
  • 88. Static(Behavior)
  • 89.    2 3 6 1 2 5 Number plusOne behavior
  • 90.   
  • 91. Static(Behavior + State)
  • 92.    2 3 6 1 2 5 Number value plusOne state
  • 93.    behavior
  • 94.   
  • 95. Static(Behavior + State)
  • 96.    2 3 6 1 2 5 Number value plusOne value = value + 1 state
  • 97.    behavior
  • 98.   
  • 99. Static(Behavior + State)
  • 100.    Number Simple!
  • 101.    value plusOne value = value + 1 state
  • 102.    behavior
  • 103.   
  • 104. Static(Behavior + State)
  • 105.    Number Type
  • 106.    value plusOne value = value + 1 state
  • 107.    behavior
  • 108.   
  • 109. Static(Behavior + State)
  • 110.    2 3 6 1 2 5 Number value plusOne value = value + 1 Object
  • 111.    Type
  • 112.   instance of
  • 113.   
  • 114. To p i c s 
  • 115.    Conceptual Perspective Implementation Perspective Object & Class
  • 116. in Class-Based OOPL
  • 117.    Type
  • 118.    Number value plusOne value = value + 1 Number value plusOne value = value + 1 member variable
  • 119.    method
  • 120.    Class
  • 121.    state
  • 122.    behavior
  • 123.    Implemented By
  • 124. Static(Behavior + State)
  • 125.    2 3 6 1 2 5 Object
  • 126.    Class
  • 127.   instance of
  • 128.    Number value plusOne value = value + 1 member variable
  • 129.    method
  • 130.   
  • 131. in Java OOPL
  • 132.    Class
  • 133.    Number value plusOne value = value + 1 public  class  Number  {      int  number;      void  plusOne()  {          number  =  number  +  1 ;      }   }   syntax member variable
  • 134.    method
  • 135.   
  • 136. Object Class
  • 137. To p i c s 
  • 138.    Conceptual Perspective Implementation Perspective Object & Class
  • 139. Elevator Object
  • 140.   
  • 141. Behavior
  • 142.    moveUp(floor)
  • 143.   
  • 144. Behavior
  • 145.    moveDown(floor)
  • 146.   
  • 147. Class와
  • 148.   Method를
  • 149.   작성해
  • 150.   보세요
  • 151.    public  class  Elevator  {      void  moveUp(int  floor)  {      }      void  moveDown(int  floor)  {      }   }  
  • 152. State
  • 153.    moveUp(floor)
  • 154.    moveDown(floor)
  • 155.   
  • 156. State를
  • 157.   표현하기
  • 158.   위해
  • 159.    Member Variable을
  • 160.   추가해
  • 161.   보세요
  • 162.    public  class  Elevator  {      int  floor;        void  moveUp(int  floor)  {      }      void  moveDown(int  floor)  {      }   }  
  • 163. this
  • 164.    this
  • 165.   
  • 166. this
  • 167.    public  class  Elevator  {      int  floor;        void  moveUp(int  floor)  {          this.floor  =  floor;      }      void  moveDown(int  floor)  {          this.floor  =  floor;      }   }  
  • 168. Constraint
  • 169.    1층
  • 170.    10층
  • 171.   
  • 172. this
  • 173.    public  class  Elevator  {      int  floor;        void  moveUp(int  floor)  {          if  (floor  >  10  ||  this.floor  >=  floor)  {              return;          }   this.floor  =  floor;      }      void  moveDown(int  floor)  {          if  (floor  <1  ||  this.floor  <=  floor)  {              return;          }   this.floor  =  floor;      }   }  
  • 174. diff C C#/Java
  • 175.    Value Type(Primitive Type)
  • 176.    Reference Type
  • 177.    boolean, char, byte, short , int , long, float , double  String, Object, Array … Pointer Type ?
  • 178.   
  • 179. Stack Heap Value Type
  • 180.    ReferenceType
  • 181.    Stack & Heap
  • 182.    boolean, char, byte, short , int , long, float , double  String, Object, Array
  • 183. diff C C#/Java
  • 184.    new
  • 185.    Heap
  • 186. Object Instantiation
  • 187.    Elevator  elevator  =  new  Elevator() ;   Class = Type
  • 188.    ClassName()
  • 189.    Memory Allocation
  • 190.    Variable
  • 191.   
  • 192. Stack Heap Stack & Heap
  • 193.    floor = 1elevator address Elevator     Object
  • 194. public  class  Elevator  {        ...        public  static  void  main(String[]  args)  {          Elevator  elevator  =  new  Elevator();          System.out.println(elevator.floor);   elevator.moveUp(8);          System.out.println(elevator.floor);   elevator.moveDown(2);          System.out.println(elevator.floor);      }   }   Method Call – object.method()
  • 195.   
  • 196. new 
  • 197.    1층
  • 198.   
  • 199. public  class  Elevator  {        Elevator(int  floor)  {          this.floor  =  floor;      }        public  static  void  main(String[]  args)  {          Elevator  elevator  =  new  Elevator(1);          System.out.println(elevator.floor);   elevator.moveUp(8);          System.out.println(elevator.floor);   elevator.moveDown(2);          System.out.println(elevator.floor);      }   }   Constructor
  • 200.   
  • 201. public  class  Elevator  {   }   Default Constructor
  • 202.    public  class  Elevator  {          Elevator()  {          }   }   Compiler
  • 203.   
  • 204. public  class  Elevator  {          Elevator(int  floor)  {                  this.floor  =  floor;          }   }   Default Constructor
  • 205.    public  class  Elevator  {          Elevator(int  floor)  {                  this.floor  =  floor;          }   }   Compiler
  • 206.   
  • 207. public  class  Elevator  {        Elevator()  {          this.floor  =  1;      }      Elevator(int  floor)  {          this.floor  =  floor;      }   }   Default Constructor
  • 208.   
  • 209. public  class  Elevator  {        Elevator()  {          this(1);      }      Elevator(int  floor)  {          this.floor  =  floor;      }   }   this()
  • 210.   
  • 211. Behavior
  • 212.    moveUp()
  • 213.    10층
  • 214.   
  • 215. Behavior
  • 216.    moveDown()
  • 217.    1층
  • 218.   
  • 219. Method Overloading
  • 220.    public  class  Elevator  {      void  moveUp()  {          moveUp(10);      }      void  moveUp(int  floor)  {          if  (floor  >  10  ||  this.floor  >=  floor)  {              return;          }   this.floor  =  floor;      }      void  moveDown()  {          moveDown(1);      }      void  moveDown(int  floor)  {          if  (floor  <1  ||  this.floor  <=  floor)  {              return;          }   this.floor  =  floor;      }  
  • 221. 연습문제
  • 222.    [6-1], [6-2], [6-3], [6-4], [6-5]
  • 223.    p209
  • 224.   
  • 225. static  void  moveUp(Elevator  elevator)  {          elevator.moveUp(10);   }     public  static  void  main(String[]  args)  {          Elevator  elevator1  =  new  Elevator(1);          moveUp(elevator1);          System.out.println("Elevator1  "  +  elevator1.floor);   }   Call by Reference
  • 226.   
  • 227. Stack Heap Stack & Heap
  • 228.    floor = 1elevator1 Elevator     Object
  • 229. Stack Heap Stack & Heap
  • 230.    floor = 1elevator1 Elevator     Object elevator
  • 231. Stack Heap Stack & Heap
  • 232.    floor = 10elevator1 Elevator     Object elevator
  • 233. Stack Heap Stack & Heap
  • 234.    floor = 10elevator1 Elevator     Object
  • 235. static  void  swap(Elevator  elevator1,  Elevator  elevator2)  {          Elevator  temp  =  elevator1;          elevator1  =  elevator2;          elevator2  =  temp;          System.out.println("Elevator1  "  +  elevator1.floor);          System.out.println("Elevator2  "  +  elevator2.floor);   }     public  static  void  main(String[]  args)  {          Elevator  elevator1  =  new  Elevator(1);          Elevator  elevator2  =  new  Elevator(10);          swap(elevator1,  elevator2);          System.out.println("Elevator1  "  +  elevator1.floor);          System.out.println("Elevator1  "  +  elevator2.floor);   }   Swap
  • 236.   
  • 237. Stack Heap Stack & Heap
  • 238.    floor = 1elevator1 Elevator     Object floor = 10elevator2
  • 239. Stack Heap Stack & Heap
  • 240.    floor = 1elevator1 Elevator     Object floor = 10elevator2 elevator1 elevator2
  • 241. Stack Heap Stack & Heap
  • 242.    floor = 1elevator1 Elevator     Object floor = 10elevator2 elevator1 elevator2
  • 243. Stack Heap Stack & Heap
  • 244.    floor = 1elevator1 Elevator     Object floor = 10elevator2