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.
_______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners