Re: Obj-C, class methods and instance methods
Re: Obj-C, class methods and instance methods
- Subject: Re: Obj-C, class methods and instance methods
- From: Ondra Cada <email@hidden>
- Date: Sun, 19 May 2002 20:25:22 +0200
On Sunday, May 19, 2002, at 07:12 , Sanj W. wrote:
Im trying to understand the difference between class methods and instance
methods in Obj-C. I thought that class methods are similar to static
methods
in Java, where one could call the method without instantiating an class.
Yup, though the similarity does not get too far (in ObjC, you can use
freely super/self in class methods).
However, I could write the following class without a constructor (init)
and
There is always the "constructor" init inherited from NSObject.
That's one of many huge advantages of ObjC over C++ or Java: ObjC
"cosntructors" (init...) and "desctructors" (dealloc) are absolutely plain
methods, which are not different from all the other ones (the only
difference lays in the library conventions). Therefore, (a) the ObjC model
is much simpler to learn and use, and (b) both "constructors" and
"desctructors" are freely inherited.
have an instance method (an IBAction) and get the system to call it (by
merely connecting in IB).
* How does this work? It would have made sense to me if myAction was
declared as a class method.
Nope. You use only instances in IB. Presumably, you made one there (by
selecting "MyClass" and using "Instantiate" from its context menu).
Although there are some technical differences you can learn about in NIB
documentation, from practical point of view that is just as good as
calling "[[MyClass alloc] init]" in your code.
* Is there a default constructor in in the following class that I
declared?
So far as it is not a new root class, there is always inherited init (just
like a big bunch of other inherited methods, documented in NSObject.html).
---
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
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.