Article View: comp.lang.objective-c
Article #83Re: instance variable declarations..
From: Kenneth Lerman
Date: Wed, 02 Sep 1992 10:57
Date: Wed, 02 Sep 1992 10:57
74 lines
3513 bytes
3513 bytes
In article <19385@ector.cs.purdue.edu> kane@cs.purdue.edu (Christopher Kane) writes: > |In article <MAS.92Aug30121306@csa.bu.edu>, mas@csa.bu.edu writes: |> Why is it that instance variables are declared in an object's |> @interface portion (interface file) while an object's method's are in |> the @implementation portion (implementation file)? ... |Reason #2: Brad Cox designed Objective-C to require the instance | variables in the @interface; putting them in the @implemenation | is just for convenience. ... While Brad was responsible for the original Objective-C, it is my understanding that he had little to do with the modern Objective-C language (Objective-C 4.0 and above). | | From _Object_Oriented_Programming:_An_Evolutionary_Approach_, | Brad J. Cox and Andrew J. Novobilski, 2nd ed., page 89: | (quoted without permission) | | I find it convenient to provide all superclass and instance | variable information in both files, even though Objective-C | only requires this information in the interface file. If you | adhere to the first philosophy, you may omit the superclass | and instance variable information from your implementation | file, and will therefore need to read source code across two | files. By duplicating the information about instance variables | and superclass information, it is available in the same file | with the methods. When the information is present in both | files, the compiler requires that it match exactly. | | ... Of course, a decent editor would make the superclass and instance variable information in the interface file look as if it were in the implementation file and make it available for editing. ... |Subclasses of a class need to have the instance variable information |for the class as well, so the @interface section is the most convenient |place to put them. | |I (partially) feel the way you do, though. There are sometimes |instance variables in a class which a subclass should not modify, |either because consistancy between several variables is necessary, |or the variable is a relatively complex data structure (eg, a linked |list) of which you don't want to document the internals, or is |simply private (in some way of thinking) to the class and subclasses |should not need to "know" about it (in the way that methods not listed |in the interface file are not "known", but are inherited as usual). |Where necessary, the class should provide methods, which the subclass |should use, to access these types of instance variables. ... agreed. | |Indexed instance variables may be the solution here; I have never |attempted to use that facility. It seems to be more trouble than |it is really worth. ... No, indexed instance variable are used for array-like appendages to objects. | |Christopher Kane |kane@cs.purdue.edu -- Kenneth Lerman ...!uunet!casey!gaboon!seltd!lerman Systems Essentials Limited (203)426-4430 55 Main Street Newtown, CT 06470
Technical Details
Message-ID:
<21@seltd.UUCP>Path:
arc1-ca.pugleaf.net!sparky!uunet!casey!gaboon!seltd!lermanReferences:
<MAS.92Aug30121306@csa.bu.edu> <19385@ector.cs.purdue.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!casey!gaboon!seltd!lerman From: lerman@seltd.UUCP (Kenneth Lerman) Newsgroups: comp.lang.objective-c Subject: Re: instance variable declarations.. Message-ID: <21@seltd.UUCP> Date: 2 Sep 92 10:57:30 GMT References: <MAS.92Aug30121306@csa.bu.edu> <19385@ector.cs.purdue.edu> Reply-To: lerman@seltd.UUCP (Kenneth Lerman) Organization: Systems Essentials Limited Lines: 74