Stupid Question?
Zulq Alam
me at zulq.net
Wed Jan 16 17:48:55 UTC 2008
Your original statement was that "You can't use any of the instance
methods or accessors because they don't yet exist!". I am saying you can
use them, and the do exist, although they may or may not have a value
depending on how you chose to initialize your object.
If you do not change anything, then #new will send the newly created
object #initialize. To avoid this behaviour you will need to create a
class side method and send #basicNew to create your instance and then
initialize it as you desire. Have a look at the Point example I included.
Regards,
Zulq.
Richard Eng wrote:
> I'm not finding this to be true. I have a class #GSAssignmentList. It has
> instance variable #clientId and accessor #clientId:. I do the following:
>
> self call: (GSAssignmentList new clientId: aValue)
>
> In the #initialize method for GSAssignmentList, I write to the Transcript:
>
> Transcript cr; show: 'RKE: clientId = ', clientId asString.
>
> It shows 'nil'.
>
> In #renderContentOn:, I write to the Transcript and get aValue, as expected.
> This is contrary to what you're telling me *if* the object is created with
> #clientId = aValue *before* #initialize starts to execute.
>
> You see, I need the value of aValue in order for #initialize to complete.
>
> Regards,
> Richard
>
> ----------------
> Zulq Alam wrote:
>
> Hi Richard,
>
> The instance variables and methods, including accessors, exist when the
> object is created. They do not depend on the initialize method. Thus you
> can access any instance variable or call any defined method, such as
> accessors, at any time after creation. Whether they have a value or
> return anything useful depends on your object and how you *chose* to
> initialize it.
>
> The use of #initialize is a convention to set-up object state *after*
> the object has been created.
>
>
>
>
More information about the Squeak-dev
mailing list
|