[nhn next] java 강의- week3

103
PL in Java Week03 Inheritance 조영호 [email protected] 상속

Upload: youngho-cho

Post on 10-May-2015

2.128 views

Category:

Software


2 download

DESCRIPTION

Java 강의 3주차

TRANSCRIPT

Page 1: [NHN NEXT] Java 강의- Week3

PL����������� ������������������  in����������� ������������������  Java����������� ������������������  ����������� ������������������  Week03����������� ������������������  

I n h e r i t a n c e

조영호����������� ������������������  [email protected]����������� ������������������  

상속

Page 2: [NHN NEXT] Java 강의- Week3

Conceptual Perspective����������� ������������������  

Implementation Perspective����������� ������������������  

객체지향����������� ������������������  Object-Orientation����������� ������������������  

개념����������� ������������������  관점����������� ������������������  

구현����������� ������������������  관점����������� ������������������  

Page 3: [NHN NEXT] Java 강의- Week3

Conceptual Perspective����������� ������������������  

Implementation Perspective����������� ������������������  

객체지향����������� ������������������  Object-Orientation����������� ������������������  

개념����������� ������������������  관점����������� ������������������  

구현����������� ������������������  관점����������� ������������������  

Type����������� ������������������  

Class����������� ������������������  

Page 4: [NHN NEXT] Java 강의- Week3

Conceptual Perspective����������� ������������������  

Implementation Perspective����������� ������������������  

객체지향����������� ������������������  Object-Orientation����������� ������������������  

개념����������� ������������������  관점����������� ������������������  

구현����������� ������������������  관점����������� ������������������  

Generalization����������� ������������������  

Inheritance����������� ������������������  

Page 5: [NHN NEXT] Java 강의- Week3

To p i c s ����������� ������������������  

Inheritance

Generalization

Composition

Method Overriding

super

super()

Page 6: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  

요츠바����������� ������������������  5살����������� ������������������  

Page 7: [NHN NEXT] Java 강의- Week3

class Person { String name; int age; Person() { this("사람", 1); } Person(String name, int age) { this.name = name; this.age= age; } String introduce() { return "이름 : " + name + ", 나이 " + age + "세"; }}

Person����������� ������������������  

Person yotsuba = new Person("요츠바", 5);System.out.println(yotsuba.introduce());

Page 8: [NHN NEXT] Java 강의- Week3

Person yotsuba = new Person("요츠바", 5);

name = 요츠바 age = 5����������� ������������������  

Person

new Person()����������� ������������������  

Page 9: [NHN NEXT] Java 강의- Week3

킬러����������� ������������������  

Page 10: [NHN NEXT] Java 강의- Week3

class Killer { String name; int age; String warning; String weapon; Killer(String name, int age, String warning, String weapon) { this.name = name; this.age = age; this.warning = warning; this.weapon = weapon ; } String introduce() { return "이름 : " + name + ", 나이 " + age + "세"; } String getWeapon() { return weapon; }}

Killer����������� ������������������  

Killer killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");System.out.println(killerYotsuba.introduce());System.out.println(killerYotsuba.getWeapon());

Page 11: [NHN NEXT] Java 강의- Week3

Killer killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");

name = 요츠바 age = 5 warning = You.. weapon = 총 ����������� ������������������  

Killer

new Killer()����������� ������������������  

Page 12: [NHN NEXT] Java 강의- Week3

Person & Killer����������� ������������������  

Person����������� ������������������  name age����������� ������������������  

introduce()����������� ������������������  

Killer����������� ������������������  name age warning weapon����������� ������������������  

introduce() getWeapon()����������� ������������������  

Page 13: [NHN NEXT] Java 강의- Week3

Code Duplication����������� ������������������  

Person����������� ������������������  name age����������� ������������������  

introduce()����������� ������������������  

Killer����������� ������������������  name age warning weapon����������� ������������������  

introduce() getWeapon()����������� ������������������  

Page 14: [NHN NEXT] Java 강의- Week3

Inheritance����������� ������������������  

Person����������� ������������������  name age����������� ������������������  

introduce()����������� ������������������  

Killer����������� ������������������   warning weapon����������� ������������������  

getWeapon()����������� ������������������  

Page 15: [NHN NEXT] Java 강의- Week3

class Killer extends Person { String warning; String weapon; Killer(String name, int age, String warning, String weapon) { this.name = name; this.age = age; this.warning = warning; this.weapon = weapon; } String getWeapon() { return weapon; } }

Killer extends Person����������� ������������������  

Page 16: [NHN NEXT] Java 강의- Week3

Person yotsuba = new Person("요츠바", 5);

name = 요츠바 age = 5����������� ������������������  

Person

Killer killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");

name = 요츠바 age = 5 warning = You.. weapon = 총 ����������� ������������������  

Killer

Member Variable Inheritance����������� ������������������  

Page 17: [NHN NEXT] Java 강의- Week3

Person yotsuba = new Person("요츠바", 5);System.out.println(yotsuba.introduce());Killer killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");System.out.println(killerYotsuba.introduce());System.out.println(killerYotsuba.getWeapon());

Method Inheritacne����������� ������������������  

Page 18: [NHN NEXT] Java 강의- Week3

음악가����������� ������������������  

Page 19: [NHN NEXT] Java 강의- Week3

Person Code Reuse����������� ������������������  

Page 20: [NHN NEXT] Java 강의- Week3

Inheritance����������� ������������������  

Person����������� ������������������  name age����������� ������������������  

introduce()����������� ������������������  

Musican����������� ������������������   instrument

play()����������� ������������������  

Page 21: [NHN NEXT] Java 강의- Week3

public class Musician extends Person { String instrument; Musician(String name, int age, String instrument) { this.name = name; this.age = age; this.instrument = instrument; } String play() { return instrument + " 연주"; }}

Musician extends Person����������� ������������������  

Musician musicanYotsuba = new Musician("요츠바", 5, "피리");System.out.println(musicanYotsuba.introduce());System.out.println(musicanYotsuba.play());

Page 22: [NHN NEXT] Java 강의- Week3

Code Reuse����������� ������������������  

Inheritance����������� ������������������  

Remove Code Duplication����������� ������������������  

Page 23: [NHN NEXT] Java 강의- Week3

Root Class����������� ������������������  

Object����������� ������������������  

Page 24: [NHN NEXT] Java 강의- Week3

class Person {}

Object����������� ������������������  

class Person extends Object {}

Page 25: [NHN NEXT] Java 강의- Week3

To p i c s ����������� ������������������  

Inheritance

Generalization

Composition

Method Overriding

super

super()

Page 26: [NHN NEXT] Java 강의- Week3

사람과����������� ������������������  킬러����������� ������������������  

Page 27: [NHN NEXT] Java 강의- Week3

사람과����������� ������������������  킬러����������� ������������������  더����������� ������������������  일반적인����������� ������������������  개념����������� ������������������  

Page 28: [NHN NEXT] Java 강의- Week3

사람과����������� ������������������  킬러����������� ������������������  더����������� ������������������  특수한����������� ������������������  개념����������� ������������������  

Page 29: [NHN NEXT] Java 강의- Week3

왜?����������� ������������������  

Page 30: [NHN NEXT] Java 강의- Week3

왜?����������� ������������������  의미적으로����������� ������������������  킬러를����������� ������������������  포괄하면서

더����������� ������������������  적은����������� ������������������  설명����������� ������������������  필요����������� ������������������  

Page 31: [NHN NEXT] Java 강의- Week3

사람의����������� ������������������  개념을����������� ������������������  포함하는 더����������� ������������������  많은����������� ������������������  설명����������� ������������������  필요����������� ������������������  

왜?����������� ������������������  

Page 32: [NHN NEXT] Java 강의- Week3

이����������� ������������������  세상에는����������� ������������������  사람이����������� ������������������  더����������� ������������������  많을까요?����������� ������������������  킬러가����������� ������������������  더����������� ������������������  많을까요?����������� ������������������  

Page 33: [NHN NEXT] Java 강의- Week3
Page 34: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  

Page 35: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  킬러����������� ������������������  

Page 36: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  킬러����������� ������������������  더����������� ������������������  일반적인����������� ������������������  개념����������� ������������������  

더����������� ������������������  특수한����������� ������������������  개념����������� ������������������  

Page 37: [NHN NEXT] Java 강의- Week3

일반화와����������� ������������������  특수화����������� ������������������  일반화����������� ������������������   특수화����������� ������������������  

Page 38: [NHN NEXT] Java 강의- Week3

일반화와����������� ������������������  특수화����������� ������������������  일반화����������� ������������������   특수화����������� ������������������  

설명은����������� ������������������  더����������� ������������������  추상적이고 집합의����������� ������������������  크기는����������� ������������������  더����������� ������������������  크고����������� ������������������  

Page 39: [NHN NEXT] Java 강의- Week3

일반화와����������� ������������������  특수화����������� ������������������  일반화����������� ������������������   특수화����������� ������������������  

설명은����������� ������������������  더����������� ������������������  구체적이고 집합의����������� ������������������  크기는����������� ������������������  더����������� ������������������  작고����������� ������������������  

Page 40: [NHN NEXT] Java 강의- Week3

일반화와����������� ������������������  특수화����������� ������������������  일반화����������� ������������������   특수화����������� ������������������  

특수화����������� ������������������  집합은����������� ������������������  일반화����������� ������������������  집합의����������� ������������������  부분집합����������� ������������������  

Page 41: [NHN NEXT] Java 강의- Week3

is-a Relationship����������� ������������������  

Killer is-a Person����������� ������������������  

Page 42: [NHN NEXT] Java 강의- Week3

in OO����������� ������������������  

Concept == Type����������� ������������������  

Page 43: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  킬러����������� ������������������  Type

Type

Page 44: [NHN NEXT] Java 강의- Week3

in OO����������� ������������������  

Type Class����������� ������������������  implementation

Page 45: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  킬러����������� ������������������  Class

Class

Page 46: [NHN NEXT] Java 강의- Week3

class  Person  {      String  name;      int  age;            String  introduce()  {      }  }  

Person & Killer����������� ������������������  

class  Killer  extends  Person  {      String  warning;      String  weapon;      String  getWeapon()  {      } }  

더����������� ������������������  추상적인����������� ������������������  설명����������� ������������������  

더����������� ������������������  구체적인����������� ������������������  설명����������� ������������������  

Page 47: [NHN NEXT] Java 강의- Week3

Killer  killerYotsuba  =  new  Killer("요츠바",  5,                                      "You  can  tell  me  in  hell.",  "총");  

name = 요츠바 age = 5 warning = You.. weapon = 총 ����������� ������������������  

Killer

Person

Page 48: [NHN NEXT] Java 강의- Week3

Killer  killerYotsuba  =  new  Killer("요츠바",  5,                                      "You  can  tell  me  in  hell.",  "총");  

name = 요츠바 age = 5 warning = You.. weapon = 총 ����������� ������������������  

Killer

Person

Person  yotsuba  =  new  Killer("요츠바",  5,                                      "You  can  tell  me  in  hell.",  "총");  

Page 49: [NHN NEXT] Java 강의- Week3

Person����������� ������������������  Killer����������� ������������������  Class

Class

new Killer()����������� ������������������  

new Killer()����������� ������������������  

new Killer()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

new Person()����������� ������������������  

Page 50: [NHN NEXT] Java 강의- Week3

class  Person  {      String  name;      int  age;            String  introduce()  {      }  }  

Person & Killer����������� ������������������  

class  Killer  extends  Person  {      String  warning;      String  weapon;      String  getWeapon()  {      } }  

일반화����������� ������������������  

특수화����������� ������������������  

Page 51: [NHN NEXT] Java 강의- Week3

in OO����������� ������������������  

Type Type����������� ������������������  

Generalization Specialization

Page 52: [NHN NEXT] Java 강의- Week3

in OO����������� ������������������  

Class Class����������� ������������������  Inheritance

Page 53: [NHN NEXT] Java 강의- Week3

in OO����������� ������������������  

Generalization Inheritance����������� ������������������  

implementation

Page 54: [NHN NEXT] Java 강의- Week3

To p i c s ����������� ������������������  

Inheritance

Generalization

Composition

Method Overriding

super

super()

Page 55: [NHN NEXT] Java 강의- Week3

Method Overloading?����������� ������������������  

Page 56: [NHN NEXT] Java 강의- Week3

Method Overloading����������� ������������������  public class Elevator { Elevator() { ... } Elevator(int floor) { ... } void moveUp() { ... } void moveUp(int floor) { ... } void moveDown() { ... } void moveDown(int floor) { ... }}

Page 57: [NHN NEXT] Java 강의- Week3

Method Overriding?����������� ������������������  

Page 58: [NHN NEXT] Java 강의- Week3

this

Page 59: [NHN NEXT] Java 강의- Week3

class Person { String name; int age; ... String introduce() { return "이름 : " + name + ", 나이 " + age + "세"; }}

Person yotsuba = new Person("요츠바", 5);

name = 요츠바 age = 5����������� ������������������  

this class  Person  String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }

class

class  Object

superclass

 String  toString()  {  ...  }  

Page 60: [NHN NEXT] Java 강의- Week3

Method Lookup

this에서����������� ������������������  시작����������� ������������������  

Page 61: [NHN NEXT] Java 강의- Week3

class Person { String introduce() { return "이름 : " + name + ", 나이 " + age + "세"; }}

name = 요츠바 age = 5����������� ������������������  

this class  Person  String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }

class

class  Object

superclass

 String  toString()  {  ...  }  

yotsuba.introduce()

Page 62: [NHN NEXT] Java 강의- Week3

class  Person  {    String  introduce()  {          return  "이름 :  "  +  name  +  ",  나이 "  +  age  +  "세";      }  }  

name = 요츠바 age = 5����������� ������������������  

this class  Person  String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }

class

class  Object

superclass

 String  toString()  {  ...  }  

yotsuba.toString()

Page 63: [NHN NEXT] Java 강의- Week3

class Killer extends Person { }

class Person { String introduce() { return "이름 : " + name + ", 나이 " + age + "세"; }}

Person yotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person  String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

Page 64: [NHN NEXT] Java 강의- Week3

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person  String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

yotsuba.introduce()

class  Killer  extends  Person  {      }  

class  Person  {      String  introduce()  {          return  "이름 :  "  +  name  +  ",  나이 "  +  age  +  "세";      }  }  

Page 65: [NHN NEXT] Java 강의- Week3

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person  String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

yotsuba.introduce()

 String  introduce()  {    return  "무기 :  "  +  weapon  +  ","  +            "이름 :  "  +  name  +            ",  나이 "  +  age  +  "세";      }

class Killer extends Person { String introduce() { return "무기 : " + weapon + "," + "이름 : " + name + ", 나이 " + age + "세"; } }

class Person { String introduce() { return "이름 : " + name + ", 나이 " + age + "세"; }}

class  Object

Page 66: [NHN NEXT] Java 강의- Week3

Killer의����������� ������������������  introduce()가����������� ������������������  

Person의����������� ������������������  introduce()를����������� ������������������  

감춤����������� ������������������  

Page 67: [NHN NEXT] Java 강의- Week3

Method Overriding?����������� ������������������  

Page 68: [NHN NEXT] Java 강의- Week3

To p i c s ����������� ������������������  

Inheritance

Generalization

Composition

Method Overriding

super

super()

Page 69: [NHN NEXT] Java 강의- Week3

Method Lookup

this에서����������� ������������������  시작����������� ������������������  

Page 70: [NHN NEXT] Java 강의- Week3

this

메시지를����������� ������������������  수신한����������� ������������������  현재����������� ������������������  객체����������� ������������������  

현재����������� ������������������  클래스����������� ������������������  

Page 71: [NHN NEXT] Java 강의- Week3

public class Person { String message() { return "Message : [" + introduce() + "]"; }

String introduce() { return "이름: " + name + ", 나이: " + age + "세"; }}

public class Killer extends Person { String introduce() { return "무기 : " + weapon + "," + "이름 : " + name + ", 나이 " + age + "세"; }}

Quiz

Person killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");killerYotsuba.message();

Page 72: [NHN NEXT] Java 강의- Week3

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person String message() { return "Message : [" + introduce() + "]"; }

String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }  

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

 String  introduce()  {        return  "무기 :  "  +  weapon  +  ","  +            "이름 :  "  +  name  +            ",  나이 "  +  age  +  "세";      }

Person killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");

killerYotsuba.message(); class  Object

this부터����������� ������������������  Look����������� ������������������  Up����������� ������������������  

Page 73: [NHN NEXT] Java 강의- Week3

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person String message() { return "Message : [" + introduce() + "]"; }

String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }  

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

 String  introduce()  {        return  "무기 :  "  +  weapon  +  ","  +            "이름 :  "  +  name  +            ",  나이 "  +  age  +  "세";      }

Person killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");killerYotsuba.message();

class  Object

introduce()

Page 74: [NHN NEXT] Java 강의- Week3

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person String message() { return "Message : [" + introduce() + "]"; }

String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }  

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

 String  introduce()  {        return  "무기 :  "  +  weapon  +  ","  +            "이름 :  "  +  name  +            ",  나이 "  +  age  +  "세";      }

Person killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");killerYotsuba.message();

class  Object

introduce()

this부터����������� ������������������  Look����������� ������������������  Up����������� ������������������  

Page 75: [NHN NEXT] Java 강의- Week3

name = 요츠바 age = 5 warning = You.. weapon = 총

����������� ������������������  

this

class  Person String message() { return "Message : [" + introduce() + "]"; }

String  introduce()  {    return  "이름 :  "  +  name  +              ",  나이 "  +  age  +  "세";      }  

class

class  Object

superclass

 String  toString()  {  ...  }  

class  Killer

superclass

 String  introduce()  {        return  "무기 :  "  +  weapon  +  ","  +            "이름 :  "  +  name  +            ",  나이 "  +  age  +  "세";      }

Person killerYotsuba = new Killer("요츠바", 5, "You can tell me in hell.", "총");killerYotsuba.message();

class  Object

introduce()

this부터����������� ������������������  Look����������� ������������������  Up����������� ������������������  

Page 76: [NHN NEXT] Java 강의- Week3

this Dynamic����������� ������������������  

Page 77: [NHN NEXT] Java 강의- Week3

super

Page 78: [NHN NEXT] Java 강의- Week3

Method Lookup

부모����������� ������������������  클래스에서����������� ������������������  시작����������� ������������������  

Page 79: [NHN NEXT] Java 강의- Week3

public class Person { String introduce() { return "이름: " + name + ", 나이: " + age + "세"; } }

public class Killer extends Person { String introduce() { return "무기 : " + weapon + "," + "이름 : " + name + ", 나이 " + age + "세"; }}

Code Duplication

Page 80: [NHN NEXT] Java 강의- Week3

public class Person { String introduce() { return "이름: " + name + ", 나이: " + age + "세"; } }

public class Killer extends Person { String introduce() { return "무기 : " + weapon + "," + introduce(); }} Recursive Call

Code Reuse

Page 81: [NHN NEXT] Java 강의- Week3

public class Person { String introduce() { return "이름: " + name + ", 나이: " + age + "세"; } }

public class Killer extends Person { String introduce() { return "무기 : " + weapon + "," + super.introduce(); }}

super

Page 82: [NHN NEXT] Java 강의- Week3

super

super가����������� ������������������  있는����������� ������������������  클래스의����������� ������������������  부모����������� ������������������  클래스����������� ������������������  

현재����������� ������������������  객체����������� ������������������  

Page 83: [NHN NEXT] Java 강의- Week3

super Static����������� ������������������  

Page 84: [NHN NEXT] Java 강의- Week3

To p i c s ����������� ������������������  

Inheritance

Generalization

Composition

Method Overriding

super

super()

Page 85: [NHN NEXT] Java 강의- Week3

this()

Page 86: [NHN NEXT] Java 강의- Week3

this()����������� ������������������  class Person { Person() { this("사람", 1); } Person(String name, int age) { this.name = name; this.age= age; }}

Page 87: [NHN NEXT] Java 강의- Week3

class Killer extends Person { Killer(String name, int age, String warning, String weapon) { this.name = name; this.age = age; this.warning = warning; this.weapon = weapon; }}

class Person { Person() { this("사람", 1); } Person(String name, int age) { this.name = name; this.age= age; }}

Code Duplication

Page 88: [NHN NEXT] Java 강의- Week3

super()

Page 89: [NHN NEXT] Java 강의- Week3

class Killer extends Person { Killer(String name, int age, String warning, String weapon) { super(name, age); this.warning = warning; this.weapon = weapon; }}

class Person { Person() { this("사람", 1); } Person(String name, int age) { this.name = name; this.age= age; }}

Code Duplication

Page 90: [NHN NEXT] Java 강의- Week3

To p i c s ����������� ������������������  

Inheritance

Generalization

Composition

Method Overriding

super

super()

Page 91: [NHN NEXT] Java 강의- Week3

아이언맨����������� ������������������  

Page 92: [NHN NEXT] Java 강의- Week3

class  IronMan  extends  Person  {   }  

?����������� ������������������  

Page 93: [NHN NEXT] Java 강의- Week3

사람����������� ������������������  킬러����������� ������������������  

아이언맨����������� ������������������  

?����������� ������������������  

Page 94: [NHN NEXT] Java 강의- Week3

IronMan����������� ������������������   Person����������� ������������������  

Page 95: [NHN NEXT] Java 강의- Week3

Composition����������� ������������������  

Not Generalization����������� ������������������  

Page 96: [NHN NEXT] Java 강의- Week3

class  IronMan  {      Person  person;        IronMan(Person  person)  {          this.person  =  person;      }  }  

합성Composition����������� ������������������  

IronMan  ironMan  =        new  IronMan(new  Person("토니 스타크",  40));    IronMan  ironYotsuba  =        new  IronMan(new  Killer("요츠바",  5,                "You  can  tell  me  in  hell.",  "총"));  

Page 97: [NHN NEXT] Java 강의- Week3

사람����������� ������������������   킬러����������� ������������������  아이언맨����������� ������������������  

포함����������� ������������������  

Page 98: [NHN NEXT] Java 강의- Week3

아이언맨이����������� ������������������  말을����������� ������������������  하는����������� ������������������  것이����������� ������������������  아니라����������� ������������������  

Page 99: [NHN NEXT] Java 강의- Week3

안에����������� ������������������  들어����������� ������������������  있는����������� ������������������  사람이����������� ������������������  말을����������� ������������������  하는����������� ������������������  것이죠����������� ������������������  

Page 100: [NHN NEXT] Java 강의- Week3

public  class  IronMan  {      Person  person;        IronMan(Person  person)  {          this.person  =  person;      }      String  introduce()  {          return  person.introduce();      }  }  

위임Delegation����������� ������������������  

Page 101: [NHN NEXT] Java 강의- Week3

has-a Relationship����������� ������������������  

IronMan has-a Person����������� ������������������  

Page 102: [NHN NEXT] Java 강의- Week3

Code Reuse����������� ������������������  

Inheritance����������� ������������������  

Composition����������� ������������������  

White-Box Reuse����������� ������������������  

Black-Box Reuse����������� ������������������  

Page 103: [NHN NEXT] Java 강의- Week3

Favor composition over inheritance