• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Q's about Obj-C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Q's about Obj-C


  • Subject: Re: Q's about Obj-C
  • From: Joe Chan <email@hidden>
  • Date: Mon, 15 Oct 2001 12:52:42 -0400

Actually, the language _NEVER_ requires message declaration.

If you know plain C well, consider function headers. In ObjC, it's _EXACTLY_
the same: the only difference is that an "unknown" function would return an
int, whilst an unknown message would return an id (those are convertible
anyway).

I thought the unknown part only applies to return values, not function.

Apart of that, you would want to declare
(a) all new _PUBLIC_ messages, so that the compiler knows them and would not warn;
(b) those "old" (ie. known to compiler from any other header) messages which
are implemented in some non-quite-obvious way, so as you can comment on that
in headers;
(c) those "old" messages which you seldom overwrite, in cases when another
user of your class would need to know that.

As for (a), if you have some methods which are used only internally, don't
ever declare the appropriate messages in header. If needed (to suppress
warnings), do that in a category in implementation.

As for (c), a good example might be awakeFromNib, so as anybody who might
want to subclass your class knows that if he uses it, a [super awakeFromNib]
would be in order.


Then is it fair to say that the declarations of messages in .h is strictly speaking not required by the language? I'm still a little confused. For example is:

@interface A : NSObject
@end;

@implementation A
- (int) foo { /* new method */
return 1;
}
@end

legal?

id o;
[o foo:1]; // issues a warning, and compiles randomly (A) or (B)

I thought that because the runtime selects the method, it won't really be randam, will it? It will either be calling A's or B's or forwarded (if it's setup to do so), right?

[(A*)o foo:1]; // converts 1 to double (A)
[(B*)o foo:1]; // uses 1 as an integer (B)

JC> 4. What makes a class an abstract class? In C++, that's caused
JC> by a pure virtual function, but there doesn't seem to an
JC> equivalent in Obj-C.

What is it "an abstract class"? ;))))

In dynamic system, you can't prevent instantialization compile-time like in
C++. What's better, you don't want to: since the alloc/init messages are so
much more flexible than the constructor stuff, you can use class clusters
instead (ie. an "abstract" class _can_ be instantialized, but makes in fact
an instance of an appropriate concrete subclass).

Oh, I'm not asking in the context of instantiation, just what does the docs mean when it says "abstract."

---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc


  • Follow-Ups:
    • Re: Q's about Obj-C
      • From: "Erik M. Buck" <email@hidden>
    • Re: Q's about Obj-C
      • From: Ondra Cada <email@hidden>
    • Re: Q's about Obj-C
      • From: email@hidden
References: 
 >Re: Q's about Obj-C (From: Ondra Cada <email@hidden>)

  • Prev by Date: printing an NSTableView
  • Next by Date: Re: NSTextView and nextKeyView
  • Previous by thread: Re: Q's about Obj-C
  • Next by thread: Re: Q's about Obj-C
  • Index(es):
    • Date
    • Thread