Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!uunet!abvax!iccgcc!klimas From: klimas@iccgcc.decnet.ab.com Newsgroups: comp.lang.smalltalk Subject: Re: Access methods - New feature ? Message-ID: <4441.281d9cfe@iccgcc.decnet.ab.com> Date: 30 Apr 91 21:36:14 GMT References: <1991Apr21.221149.8057@vuse.vanderbilt.edu> <4753@m5.COM> <1264@argosy.UUCP> Lines: 34 In article <1264@argosy.UUCP>, kentb@argosy.UUCP (Kent Beck) writes: > Tim Atkins writes: "Another point that has not been made is that good OO > programming style asserts that instance variables should always be accessed > indirectly through methods, even by methods of the same class and > its subclasses." > > This is only true in the presence of private methods. In Smalltalk if you > choose to use the above style in a class and its subclasses you cannot > reasonable prevent external reliance on the same structure information. > I choose to accept the occasional hassle of doing an inst var refs and > adding a few "self "s rather than expose all of my instance variables > to raping and plundering. Purists will say that Smalltalk should have > private methods- well the one I make my living on now doesn't, so I > make do with what I have. > > Kent Please folks, read the excellent article "Variables Limit Reusability" by Allen Wirf-Brock and Brian Wilkerson in the May/June 89 JOOP. Basically ALL instance variables (PUBLIC & PRIVATE) should be manipulated via getter and setter methods because it becomes SIGNIFICANTLY easier to do maintenance on the system later. Through actual industrial experience, this advice has proven to be exceptionally sound! BTW some claim that this practise wastes CPU resources whereas even in a tight loop. Profiling will show that the CPU overhead is miniscule when used in getter/setter methods (i.e. using anInstanceVariable ^self anInstanceVariable anInstanceVariable: aValue anInstanceVariable := aValue ).