Reputation: 43
I need to make a new subclass method to a new classs that i created who got 2 class instance varribles : isInterface and behavesLike. i need to make a subclass method that gets this parameters as well and creates a new sub class with thos parameters. i just cant get what am i doing wrong here . this is my code :
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).
i just keep getting those errors :
Upvotes: 1
Views: 452
Reputation: 948
You are mixing class and instance level, a very frequent issue.
Classes are artifacts that create instances. And instVars are, precisely, in the instances. In your case,
(m class) instVarNamed:'behavesLike' put:aCollection
attempts to set the instance var of a class, because m class is a class. If you want an instance, you should talk to m class new, but even worse, because m itself is a class, so m class is a metaclass. To understand all this confusion, you should read the chapters about Metaclasses in the Blue Book.
But to fix your code, m new
instead of m class
should work
Upvotes: 1