• 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 Catch-22
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing Catch-22


  • Subject: Re: Subclassing Catch-22
  • From: Greg Titus <email@hidden>
  • Date: Tue, 26 Apr 2005 13:57:05 -0700


On Apr 26, 2005, at 20:28, Todd Ransom wrote:
I have a controller class that has methods like this:

- (BOOL)doSomething;
- (NSString *)getInformationRequiredToDoSomething;

- (BOOL)doSomething {

    NSString *info = [self getInformationRequiredToDoSomething];
    ...
}

Which works fine until I subclass. In my subclass I would like doSomething to call super for a subset of possible actions. But when I call super it calls [self getInformationRequiredToDoSomething] and returns its own info, not super's.

The pattern for this would be to make the superclass actually implement:

- (NSString *)internalInformationRequired;
{
	...
}

- (NSString *)getInformationRequiredToDoSomething
{
	return [self internalInformationRequired];
}

- (BOOL)doSomething
{
	NSString *info = [self internalInformationRequired];
}

Then even if you override getInformationRequiredToDoSomething in a subclass, the superclass's doSomething will get the original information from the superclass. But like Ondra, I suspect that there may be a better way to design this, if I had more information on what you are trying to do.

Hope this helps,
	 - Greg
	

_______________________________________________
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


  • Follow-Ups:
    • Re: Subclassing Catch-22
      • From: Todd Ransom <email@hidden>
References: 
 >Subclassing Catch-22 (From: Todd Ransom <email@hidden>)
 >Re: Subclassing Catch-22 (From: Marco Scheurer <email@hidden>)
 >Re: Subclassing Catch-22 (From: Todd Ransom <email@hidden>)

  • Prev by Date: Re: Trouble drawing a polygon...
  • Next by Date: Re: NSFileModificationDate after 2039
  • Previous by thread: Re: Subclassing Catch-22
  • Next by thread: Re: Subclassing Catch-22
  • Index(es):
    • Date
    • Thread