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 -> #bottomRight .... } asDictionary ]. cheers -ben On Thu, Jul 23, 2015 at 8:40 AM, Peter Uhnak <i.uh...@gmail.com> wrote: > 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 have some other related methods such as > ~~~~~~~~~~~ > MyRectangle>>oppositeSideFor: aSide > ^ self oppositeSides at: aSide > ~~~~~~~~~~~~ > > So it's a method returning a mapping between opposite sides/corners and thus > is really not going to change. > Now I could place this in instance-side and create a new instance every time > I wanted to use it (which doesn't seem practical), or I could put it in > class-side. > The problem I have with class-side is that naming is more like going through > minefield (more than once I corrupted my image by naming a method or > variable something I shouldn't have), and for whatever reason it feels like > either metaprogramming or procedural programmming... That class side methods > are pretty much global functions/variables... and short of constructors I am > avoiding static methods even in other languages... but maybe using it is ok. > Or maybe have it object an use singleton? > > The only oop-like approach I see would be to extend symbols (#top > oppositeSide), or have separate objects for sides, but that seems like > overkill. > > MySide subclass: #Top > > Top>>oppositeSide > ^ Bottom new > > Are there any best practices regarding this? This is also true for actual > data stored in methods/attributes (such as icons). > > P.s.: For english natives... Should the second method be ned > "oppositeSideOf:" or "oppositeSideFor:"? > > Any ideas/pointers appreciated, > Peter