Maybe more to the point: You do not want to *code a dependency on* what the
implementing class may do as far as the returned result. :^)
"Brittle code" will eventually break. Murphy's Law says that it will break
at the worst possible time for you to have to deal with it. :^D
--
Sent from: ht
ted basically
> Dog class>>newWhite
> "Returns a new white instance of receiver."
> ^self new
>color: Color white;
>yourself
is equivalent to
> Dog class>>newWhite
>"Returns a new white instance of receiver.”
> | instance |
instance := self new.
i
+1
> On 2 Aug 2020, at 19:37, Richard Sargent wrote:
>
>
>
> On August 2, 2020 10:16:54 AM PDT, tbrunz wrote:
>> Thanks, Richard.
>>
>> So adding #yourself is mostly needed for cases where you send #add: to
>> an
>> OrderedCollection (because that returns the added element instead of
>>
Got it. Seems like an important point for those who are trying to understand
the difference between instances and classes.
I've gotten strange results myself until I learned that #yourself is an
essential thing...
-t
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
On August 2, 2020 10:16:54 AM PDT, tbrunz wrote:
>Thanks, Richard.
>
>So adding #yourself is mostly needed for cases where you send #add: to
>an
>OrderedCollection (because that returns the added element instead of
>returning the collection as most expect it would)?
No.
It is used when you
Thanks, Richard.
So adding #yourself is mostly needed for cases where you send #add: to an
OrderedCollection (because that returns the added element instead of
returning the collection as most expect it would)?
I've been adding it in all cases, which I guess does no harm.
-t
--
Sent from: h
On August 2, 2020 9:25:32 AM PDT, tbrunz wrote:
>Shouldn't this code
>
>> So if you implement a #newWhite method in the "class side" of Dog, it
>> would be something like this.
>>
>> Dog class>>newWhite
>> "Returns a new white instance of receiver."
>> ^self new color: Color white
>
>be t
Shouldn't this code
> So if you implement a #newWhite method in the "class side" of Dog, it
> would be something like this.
>
> Dog class>>newWhite
> "Returns a new white instance of receiver."
> ^self new color: Color white
be this instead?
> Dog class>>newWhite
> "Returns a new white i
Hello patrick
Welcome
>
> Subject: Class side vs instance side (variables and methods)
> Date: 29 July 2020 at 01:34:22 CEST
> To: Any Question About Pharo Is Welcome
>
>
> Being new not only to Smalltalk, but OOP in general, I think I finally am
> understanding things.
Did you read my lear
Hi,
The "class vs instance" side is one of the most confusing things for
newcomers, I remember struggling with it when I learnt Smalltalk (and
also was a novice in OOP).
It helps you thinking it this way: the instance side is everything
that will affect all instances of such class, and you can th
On Tue, Jul 28, 2020 at 4:35 PM G B via Pharo-users <
pharo-users@lists.pharo.org> wrote:
> Being new not only to Smalltalk, but OOP in general, I think I finally am
> understanding things. One area I am still unsure about is the class side
> versus the instance side. Does one usually use the clas
--- Begin Message ---
Being new not only to Smalltalk, but OOP in general, I think I finally am
understanding things. One area I am still unsure about is the class side versus
the instance side. Does one usually use the class side when they want those
inherited in every subclass, which frees one
What I like with having class is that you can attach behavior
aTop opposite
-> aBottom
Le 23/7/15 02:40, Peter Uhnak a écrit :
Hi,
I am trying to figure out where to best place some mapping/data/stable
methods.
For example imagine method
~
MyRectangle>>oppositeSides
2015-07-23 14:33 GMT+02:00 Peter Uhnák :
> Cache of the mapping is just an implementation detail.
>
> I was referring to the instance of the ==MyRectangle== object;
> so I am more interested in this from outside perspective --- other objects
> that will have to use the API...
>
> So whether I woul
Cache of the mapping is just an implementation detail.
I was referring to the instance of the ==MyRectangle== object;
so I am more interested in this from outside perspective --- other objects
that will have to use the API...
So whether I would call
[[[
"class-side methods"
MyRectangle oppositeSi
Even if you put the method on the class-side, you would still be
creating an new instance each time. Maybe you can store it in a class
variable...
MyRectangle>>oppositeSides
^ oppositeSides ifNil: [ oppositeSidesCache := { #top -> #bottom.
#bottom -> #top.
#topLeft -> #bottomR
Hi,
I am trying to figure out where to best place some mapping/data/stable methods.
For example imagine method
~
MyRectangle>>oppositeSides
^ { #top -> #bottom.
#bottom -> #top.
#topLeft -> #bottomRight
} asDictionary
And then the class might hav
17 matches
Mail list logo