There are two subjects here. Let me start with Oscar's query first. Since protocols in Smalltalk are a suggestion but not enforceable, I tend to avoid (ii) as much as possible and use instance variable methods with lazy initialization as much as possible to have short initialize methods.
Pertaining to Gerben's question, I think an authoritative answer will be still needing: Looking at the class hierarchy from SimpleButtonMorph up, you'll see that bounds ivar is defined in Morph class and indeed there is a method Morph>>bounds:, but it is in geometry protocol (meaning is not in accessing protocol). Notice that Morph>>bounds: does not update bounds ivar directly, but rather indirectly via Morph>>extent:! So in this particular case using the accessor method would not work the same way as the code in the book (caveat emptor, I did not test this assertion!) Em 21/10/2009 10:12, Oscar Nierstrasz < [email protected] > escreveu: > > Hi Gerben, > It is really a question of style. Some people promote the use of > accessors aggressively for all instance variable access. The down > sides are (i) proliferation of accessor methods, and (ii) exposure > of private state to other objects. If you do decide to use > accessors, you should be sure to put them in a protocol called > "private" to make clear that they are only intended for use by the > object itself. > I am curious what other people tend to do -- do you use accessors > for inherited ivars, or access them directly? > - on > > > On 21 Oct 2009, at 11:45, Gerben van de Wiel wrote: > > > Hi, > > I am very new to Pharo and Smalltalk in general. When reading > > through the excellent PBE book i was wondering about something on > > page 32. In that piece of code the LOCell class is using some > > instance variables from it's super classes, and i was wondering if > > it isn't best practice to use message to self using the accessing > > methods so instead of. > > bounds := 0...@0 corner: 1...@16. using self bounds: (0...@0 corner: > > 1...@16). > > or is good to use both or is there something i don't know (maybe > > it is faster to use instance vars then sending a new message and > > traverse the inheritance tree). > > regards, > > Gerben van de Wiel _______________________________________________ Pharo-project mailing list [email protected] http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
