Smalltalk 在squeak中重写子类方法

Smalltalk 在squeak中重写子类方法,smalltalk,squeak,Smalltalk,Squeak,我需要为我创建的一个新类创建一个新的子类方法,该类有两个类实例变量:isInterface和behavesLike。 我需要创建一个子类方法来获取这个参数,并使用thos参数创建一个新的子类。 我就是不明白我做错了什么。 这是我的代码: subclass: aSubclassName isInterface: isInterface behavesLike: aCollection instanceVariableNames: instVarNames classVariableName

我需要为我创建的一个新类创建一个新的子类方法,该类有两个类实例变量:isInterface和behavesLike。 我需要创建一个子类方法来获取这个参数,并使用thos参数创建一个新的子类。 我就是不明白我做错了什么。 这是我的代码:

subclass: aSubclassName isInterface: isInterface behavesLike:
    aCollection instanceVariableNames: instVarNames classVariableNames:
    classVarNames poolDictionaries: poolDictionaries category:aCategoryName
|m|
    m:=(super subclass: aSubclassName
        instanceVariableNames: instVarNames
        classVariableNames:classVarNames
        poolDictionaries: poolDictionaries
        category: aCategoryName).
(m class) instVarNamed:'behavesLike' put:aCollection;instVarNamed:'isInterface' put:isInterface
            ^(m class).

我经常会遇到这样的错误:

您在混合类和实例级别,这是一个非常常见的问题

类是创建实例的构件。而InstVar正是如此。 就你而言

(m类)instVarName:'behavesLike'put:a集合

尝试设置类的实例变量,因为m class是一个类。如果您想要一个实例,您应该与m class new对话,但更糟糕的是,因为m本身是一个类,所以m class是一个元类。要理解所有这些混淆,您应该阅读蓝皮书中关于元类的章节。 但是要修复代码,
m new
而不是
m class
应该可以工作