[Newbies] Re: FileDirectory

Ron Teitelbaum 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].

Nice job!

Ron



Sincerely, 

Joe. 






  _____  

View this message in context: Re: FileDirectory
<http://forum.world.st/FileDirectory-tp4897377p4897633.html> 
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...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20160526/2245a942/attachment.htm


More information about the Beginners mailing list