home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / objectiv / 528 < prev    next >
Encoding:
Text File  |  1992-09-12  |  2.7 KB  |  72 lines

  1. Newsgroups: comp.lang.objective-c
  2. Path: sparky!uunet!math.fu-berlin.de!uniol!tpki.toppoint.de!stefki.toppoint.de!stefan
  3. From: stefan@stefki.toppoint.de (Stefan Krause)
  4. Subject: Re: instance variable declarations..
  5. Message-ID: <1992Sep12.140413.744@stefki.toppoint.de>
  6. Organization: Just Me at Home
  7. References: <MAS.92Aug30121306@csa.bu.edu> <19385@ector.cs.purdue.edu> <1992Sep2.045715.5803@panix.com> <1992Sep8.221554.18393@gmuvax2.gmu.edu>
  8. Date: Sat, 12 Sep 1992 14:04:13 MET
  9. Lines: 61
  10.  
  11. bcox@gmuvax2.gmu.edu (Brad Cox) writes:
  12. >In article <1992Sep2.045715.5803@panix.com> you write:
  13. >>In <19385@ector.cs.purdue.edu> kane@cs.purdue.edu (Christopher Kane) writes:
  14. >>Although the quoted passage is incorrectly edited, it is usually NOT
  15. >>a good idea to repeat the interface in the implementation.
  16.  
  17. >The quoted recommendation in our book reflects the voice of pragmatic
  18. >experience, not theoretical necessity. Healthy code is read more than it is
  19. >changed/written. And having to read two files, one for data & procedural
  20. >interfaces and the other for procedural implementations, really is a
  21. >hassle.
  22.  
  23. When you've taken this step, repeating the instance variable
  24. declarations in the .m file, it comes into your mind that this is
  25. unnecessary redundancy.  What do you need in a  .h  file
  26. additionally to the instance variable and method declarations?
  27.  
  28. First there is the #import directive for the superclass header
  29. file. If you have all the directories containing the header files
  30. in your cc's -I path then you can extract the directive out of
  31. the class definition:
  32.  
  33.     @implementation MyObject:Object
  34.  
  35. in the .m file becomes to
  36.  
  37.     #import <Object.h>
  38.     @interface MyObject:Object
  39.  
  40. in the .h file. Next thing are additional typedefs or #defines.
  41. In my early ObjC programs I have used some of them. But as time
  42. went by they showed up as the weak points in my program, where I
  43. couldn't reuse code and design, where the polymorphism was
  44. broken. So I've actually removed all of them. But I've left two
  45. or three #defines for some hardwired implemention restrictions
  46. (oh, blame me:-().
  47.  
  48. Thus I need a way to write these statements in the .m file. The
  49. easiest solution is the #pragma directive. And because I'm
  50. working with NeXTstep, where  the  header  files  are  in
  51. subdirectories, I use this technique for the superclass header
  52. file too:
  53.  
  54.     #pragma .h #import <objc/Object.h>
  55.     #pragma .h #define MAXADDRESS 5
  56.     @implementation MyObject:Object
  57.  
  58. in the .m file becomes to
  59.  
  60.     #import <objc/Object.h>
  61.     #define MAXADDRESS 5
  62.     @interface MyObject:Object
  63.  
  64. in the .h file. And I use a simple awk-script to extract the .h
  65. file from the .m file. If you want to see this script then let me
  66. know.
  67.  
  68. Stefan
  69. -- 
  70. Stefan Krause                          Kiel, Germany
  71. stef@tpki.toppoint.de                  Tel.(voice) +49 431 335022
  72.