SqueakByExample:12.2

From 흡혈양파의 번역工房
Revision as of 04:42, 30 August 2012 by Onionmixer (talk | contribs)
Jump to navigation Jump to search

스몰토크 오브젝트 모델을 다시 살펴보기

모든 것이 오브젝트 이기 대문에 스몰토크에서 color blue 또한 오브젝트 입니다.

Color blue -> Color blue

모든 오브젝트는 클래스의 인스턴스입니다. Color blue의 클래스는 class Color:입니다.

Color blue class  Color

흥미롭게도, 여러분은 color의 알파 값(the alpha value)을 설정하며, 즉 TranslucentColor:인, 다양한 클래스(different class)의 인스턴스를 얻습니다.

(Color blue alpha: 0.4) class  TranslucentColor

우리는 모프(morph)를 만들고 그 색상을 반투명한 색상(translucent color)으로 설정합니다:

EllipseMorph new color: (Color blue alpha: 0.4); openInWorld


여러분은 그림 12.1에 나온 효과(effect)를 볼 수 있습니다.


그림 12.1: 반투명한 타원


Rule 3에 의해, 모든 클래스는 superclass를 갖고 있습니다. TranslucentColor의 superclass는 Color이며, Color의 superclass는 오브젝트입니다:

TranslucentColor superclass        Color
Color superclass        Object


모든 것은 메세지 발송에 의해(Rule 4) 이루어지므로, blue는 Color에 대한 메세지 이며, class 그리고 alpha:는 color blue에 대한 메세지 이며, openInWorld는 타원 모프(ellipse morph)에 대한 메세지고, superclass는 TranslucentColor와 Color에 대한 메세지인 것을 추론할 수 있습니다. 각 사례의 수신자(receiver)는 오브젝트이며, 그 이유는 모든 것이 오브젝트 이지만, 동시에 이 오브젝트들의 몇몇은 클래스 이기 때문입니다.

메서드 보기(Mehod lookup)는 계층도 사슬(the inheritance chain, Rule 5)을 따르며, 그러므로, 우리가 메세지 클래스(the message class)를 Color blue alpha: 0.4의 결과에 발송하면, 그림 12.2에서 보이는 것 처럼, 클래스 오브젝트에서 대응 메서드(the corresponding method)가 발견될 때, 메세지가 취급(handle)됩니다.

그림은 is-a 관계의 본질을 캡쳐합니다. 우리의 불투명 파랑(blue) 오브젝트는 TranslucentColor 인스턴스이지만, 우리는 또한 그것이 Color 이며, 오브젝트라고 말할 수 있고, 그 이유는 이 불투명 파랑 오브젝트는(blue object) 이 클래스들의 모든 것들에서 정의된 메세지들에 반응하기 때문입니다. 사실, isKindOf: 메세지가 존재하며, 이 isKindOf: 메세지는 여러분이 주어진 클래스와 is a 와의 관계 속에 이 isKindOf:가 있는지를 알아내기 위해 어떤 객체라도 발송할 수 있는 메세지입니다:


그림 12.2: 메세지를 불투명 색상(translucent color)에 발송하기

Notes