On Fri, May 27, 2016 at 3:02 AM, Joseph Alotta <joseph.alo...@gmail.com> wrote:
>
>> 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 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?

One downside of this approach is that it can make developing/running
unit tests harder when your tests are changing global state - which is
what class variables kind-of are.

cheers -ben

>
>> 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.
>
> Sincerely,
>
> Joe.
>
>
>
> ________________________________
> View this message in context: Re: FileDirectory
> Sent from the Squeak - Beginners mailing list archive at Nabble.com.
>
> _______________________________________________
> Beginners mailing list
> Beginners@lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to