Re: Quick polymorphism and subclassing question
Re: Quick polymorphism and subclassing question
- Subject: Re: Quick polymorphism and subclassing question
- From: Keith Blount <email@hidden>
- Date: Mon, 7 Mar 2005 01:13:53 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks for the reply, much appreciated. What you
say makes sense. I don't want to return a plain old
NSTextView because my subclass provides a number of
new methods, which would mean casting to my subclass
every time you wanted to use one of them, so I think I
will go for the second option (or both, as you
suggest).
Thanks again,
Keith
--- Greg Best <email@hidden> wrote:
> I think you have two options depending on what
> you're using the
> returned object for...
>
> Because KBTextView is a subclass of NSTextView, it
> can function as its
> superclass, so I believe
>
> -(NSTextView*)textView;
>
> can return your KBTextView instance. The catch is
> that no one
> receiving it will know there's anything different
> about it, and
> depending on how you've subclassed it it might
> behave differently than
> expected.
>
> Alternately you could use your second method:
>
> > - (KBTextView *)kbTextView;
>
> which ensures that the caller gets what they asked
> for. You could also
> provide both...
>
> The first method you show is probably legal, but I
> think it's the least
> preferred.
>
> I'm sure someone here will have an answer based more
> on CS theory...
>
> Cheers--
> Greg
>
>
> > Hello,
> >
> > A very basic question, I fear, but I would be very
> > grateful if someone could clear this one up for me
> by
> > explaining to me the proper way of doing things:
> >
> > Suppose I subclass NSTextView and call my subclass
> > KBTextView. Then I use this subclassed text view
> as an
> > instance variable in another class and want to
> provide
> > an accessor method to it. What would be the proper
> way
> > of creating a name for this method? I have been
> doing
> > this:
> >
> > - (KBTextView *)textView;
> >
> > However, NSTextStorage has a -(NSTextView
> *)textView
> > method. Is this a violation of the principles of
> > polymorphism? Should all methods with the same
> name
> > have exactly the same return type? ie. Would it be
> > better to have an accessor method with a different
> > name to indicate the different return type, such
> as:
> >
> > - (KBTextView *)kbTextView;
> >
> > This is probably very obvious, but I would be very
> > thankful if someone could enlighten me.
> >
> > Many thanks,
> > Keith
>
>
__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden