Re: Convenience methods and classes
Re: Convenience methods and classes
- Subject: Re: Convenience methods and classes
- From: Greg Titus <email@hidden>
- Date: Thu, 31 Jan 2002 11:23:39 -0800
Hi Drew,
On Thursday, January 31, 2002, at 11:02 AM, Drew McCormack wrote:
I want to write a convenience constructor, but can't figure out how I
can access the Class instance from within the class method. For
example, if I want to write a method "+expression" which allocates and
initializes an "Expression", how do I allocate the expression in the
method?
Can I just do this
[self alloc]
Yes, you can. When you call a class method "self" is the class. "[self
alloc]" will work great.
Probably not.
Or do I have to rewrite the method for every subclass of Expression I
write, doing this
[SubExpression alloc]
I sure hope the latter is not right. I must be able to inherit the
class method, right?
Yep. This is one of the major differences (and advantages) of
Objective-C compares to Java or C++ (neither of which have real
inheritable class methods.)
Hope this helps,
-Greg