[Newbies] Re: FileDirectory
ron at usmedrec.com
Thu May 26 21:14:44 UTC 2016
From: Joseph Alotta
Sent: Thursday, May 26, 2016 4:32 PM
> Extra credit: Why would you use a class variable? We know that an
instance variable is used to store data within the context of an instance.
Why would you want to store data in the context of a class?
Window closeAllWindows needs to have a list of all the windows, and sends
each one the close message. Or if a instance of a class needed to
communicate with other members of its class. For example, a class of
helicopter bots that fly together as a group. They would need talk to each
other to avoid collisions.
[Ron Teitelbaum] Exactly! Well done. Any dynamic information that is
related to all or a collection of instances should be held on a class
variable. You could of course create a framework by adding another object
whose job it is to manage all these instances. Then your class variable
becomes an instance variable on your manager class. It could also be used
for a class with just one instance. Create it and store it so that it's
reused when asked for a second time. You will see that a lot,
^Instance ifNil: [Instance := self new. Instance].
View this message in context: Re: FileDirectory
Sent from the Squeak - Beginners mailing list archive
<http://forum.world.st/Squeak-Beginners-f107673.html> at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners