[Newbies] Re: FileDirectory
ron at usmedrec.com
Thu May 26 20:00:47 UTC 2016
From: Joseph Alotta
Sent: Thursday, May 26, 2016 3:02 PM
> On May 26, 2016, at 8:29 AM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote:
> One more question for you. I mentioned returning a newly created instance or a specific class from a class side method. Can you name another reason why you would write a method on the class side?
When you want the class as a whole to do something. When there is only one instance of an object and other is not desirable or logical.
For example, one compiler: two is not practical. One instance of the number Pi. One instance of Nil. Why would you need another?
[Ron Teitelbaum] if there is one instance you would still write methods on the instance side. But yes having a class side method that provides your single instance makes sense.
> Why would it be a good idea to put a method on the class side instead of the instance side? (a hint for you, I’m thinking of something where nothing is returned. (of course in Smalltalk if nothing is returned you get back self, what I mean is that nothing useful is returned)) Bonus points for 2 or more answers with or without returning
> something J.
You would put a method on the class side when the method applies to all instances of the class. For example, Window closeAllWindows. Or Process stopAllProcesses. Or Smalltalk saveImage.
I don’t think this is what you had in mind, though.
[Ron Teitelbaum] This was exactly what I had in mind. When you have a method that does something to all instances or is needed to find a specific instance it makes sense to implement that as a class side method.
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?
All the best,
View this message in context: Re: FileDirectory <http://forum.world.st/FileDirectory-tp4897377p4897621.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...
More information about the Beginners