home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / objectiv / 676 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  2.2 KB

  1. Xref: sparky comp.lang.objective-c:676 comp.sys.next.programmer:7364
  2. Newsgroups: comp.lang.objective-c,comp.sys.next.programmer
  3. Path: sparky!uunet!psinntp!afs!michael
  4. From: Michael_Pizolato@afs.com (Michael Pizolato)
  5. Subject: Re: Proper way to access superclass instance variables
  6. Message-ID: <1992Nov20.145515.269@afs.com>
  7. Followup-To: comp.lang.objective-c
  8. Sender: michael@afs.com
  9. Reply-To: Michael_Pizolato@afs.com
  10. References: <1992Nov18.213742.493@afs.com>
  11. Date: Fri, 20 Nov 1992 14:55:15 GMT
  12. Lines: 51
  13.  
  14. In article <1992Nov18.213742.493@afs.com> Michael_Pizolato@afs.com (Michael  
  15. Pizolato) writes:
  16. > A question of philosophy.  Consider the following classes:
  17. > [discussion of direct vs. method access of ivars removed]
  18.  
  19. I'd like to add to the original by suggesting that even within a class one should only refer to that class' instance variables via methods designated for that purpose, execpt of course in the ivar access methods themselves.  For example:
  20.  
  21. @interface Mumble:Object
  22.    {
  23.    int value;
  24.    }
  25. - (int)value;
  26. - setValue:(int)number;
  27. - (int)doSometingWith:anotherNumber;
  28. - (int)doSometingWrongWith:anotherNumber;
  29. @end
  30.  
  31. @implementation Mumble
  32. - (int)value
  33.    {
  34.    return value;
  35.    }
  36.  
  37. - setValue:(int)number
  38.    {
  39.    value = number;
  40.    return self;
  41.    }
  42.  
  43. - (int)doSometingWith:anotherNumber
  44.    {
  45.    return [self value] * anotherNumber;
  46.    }
  47.  
  48. - (int)doSometingWrongWith:anotherNumber
  49.    {
  50.    return value * anotherNumber;
  51.    }
  52. @end
  53.  
  54. This leads to something of a "class within a class" idea, where there is an inner layer of methods designed to provide access to the instance variables, and other methods that use these access methods to get the values they need.  There can be, however, a blurring of the lines between these two types of methods, for example if methods are implemented that appear to the user of a class to provide access to an instance variable, but which in fact cover a data representation that is implicit in other ivar val
  55. ues.  This kind of method is really neither an ivar access method nor one which does "actual work."
  56.  
  57. I know this isn't very heavy stuff, but it can become an important consideration when implementing data representations.
  58.  
  59. -Michael
  60.  
  61. --
  62. Michael_Pizolato@afs.com
  63. ~18 kyu
  64. Q16
  65. NeXTMail appreciated
  66.