• 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: subclassing question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subclassing question


  • Subject: Re: subclassing question
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 12 Jul 2003 11:53:33 -0700

On Saturday, July 12, 2003, at 11:31 AM, Koen van der Drift wrote:

Hi,

My app has a baseclass with several subclasses. At one point I need to send a notification to all objects from the subclasses of baseclass. Because all objects need to get the notification, I made the baseclass the observer. From there I call the method doSomething which is handled differently in each subclass (and does nothing in the baseclass):

in baseclass:

- (void)handleNote:(NSNotification *)note
{
float = [[note object] average];
[self doSomething:average];
}

-(void)doSomething:(float)aFloat
{}

in subclass:

-(void)doSomething:(float)aFloat
{
... really do something with float
}

The problem is, only doSomething from the baseclass is called. How can I make sure that doSomething really gets called in each subclass, not only in the base class? Maybe each subclass should be an observer instead of only the baseclass?

How do you currently register for notifications?

I take it that you have an instance (at least one) of the "baseclass" and it is that instance that is getting notifications via the handleNote callback, is that correct?

If so then your instance of your base class is sending the doSomething message to itself and hence to a version of the doSomething method that does nothing.

I think what you want is for each subclass to be registered to receive notifications, that way the messages are being sent to the actual subclass instances. You can push up the notification registration and callback method into your baseclass but do it such a way that it is your subclasses that are registered not your baseclass.

-Shawn
_______________________________________________
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.

  • Follow-Ups:
    • Re: subclassing question
      • From: Koen van der Drift <email@hidden>
References: 
 >subclassing question (From: Koen van der Drift <email@hidden>)

  • Prev by Date: subclassing question
  • Next by Date: really basic nsarray intialization question
  • Previous by thread: subclassing question
  • Next by thread: Re: subclassing question
  • Index(es):
    • Date
    • Thread