SqueakByExample:12.3

From 흡혈양파의 번역工房
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

모든 클래스는 메타클래스의 인스턴스이다

12.1 부분에서 언급했듯이, 인스턴스가 클래스가 되는 클래스는 메타클래스라고 부릅니다[1].


메타클래스는 드러나지 않습니다(묵시적) 메타클래스는 클래스를 정의할 때 스몰토크 시스템에서 자동으로 생성됩니다. 프로그래머들이 메타클래스에 관해 결코 염려할 필요가 없기 때문에, 그것들을 묵시적이라고 말합니다. 클래스를 작성할때마다, 작성된 클래스를 유일한 인스턴스로 가지는 묵시적 메타클래스가 만들어집니다.

일반적으로 클래스는 global 변수에 의해 참조가 가능합니다만, 메타클래스는 별도의 이름을 가지지 않습니다. 하지만 인스턴스가 되는 클래스를 이용하면 언제라도 메타클래스를 참조할 수 있습니다. 예를들어, Color 의 클래스는 Color class 의 인스턴스이며, Object 의 클래스는 Object class 의 인스턴스 입니다.

Color class        Color class
Object class        Object class


그림 12.3 은 각 클래스class는 이름을 가지지않는 메타클래스의 인스턴스라는걸 알려주고 있습니다.

그림 12.3: TranslucentColor 메타클래스와 그것의 super클래스


클래스 또한 객체이며, 메시지를 보내고 정보를 얻어내는일도 간단합니다. 아래 부분을 보도록 하겠습니다:

Color subclasses        {TranslucentColor}
TranslucentColor subclasses        #()
TranslucentColor allSuperclasses        an OrderedCollection(Color ObjectProtoObject)
TranslucentColor instVarNames        #('alpha')
TranslucentColor allInstVarNames        #('rgb' 'cachedDepth' 'cachedBitPattern' 'alpha')
TranslucentColor selectors        an IdentitySet(#alpha:
    #asNontranslucentColor #privateAlpha #pixelValueForDepth: #isOpaque
    #isTranslucentColor #storeOn: #pixelWordForDepth: #scaledPixelValue32 #alpha
    #bitPatternForDepth: #hash #convertToCurrentVersion:refStream:
    #isTransparent #isTranslucent #setRgb:alpha: #balancedPatternForDepth:
    #storeArrayValuesOn:)


Notes

  1. 모든 인스턴수화된 클래스는 MetaClass 에 소속되어 있다고도 합니다.