FROM : Greg Titus
DATE : Tue Apr 26 22:57:05 2005
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
DATE : Tue Apr 26 22:57:05 2005
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
| Related mails | Author | Date |
|---|---|---|
| Todd Ransom | Apr 26, 20:28 | |
| Marco Scheurer | Apr 26, 22:05 | |
| Todd Ransom | Apr 26, 22:20 | |
| Ondra Cada | Apr 26, 22:32 | |
| Greg Titus | Apr 26, 22:57 | |
| Marco Scheurer | Apr 26, 23:09 | |
| Todd Ransom | Apr 26, 23:17 | |
| Marco Scheurer | Apr 26, 23:45 | |
| Ondra Cada | Apr 26, 23:54 | |
| glenn andreas | Apr 26, 23:57 | |
| Todd Blanchard | Apr 27, 00:22 | |
| Todd Ransom | Apr 27, 00:30 | |
| Ondra Cada | Apr 27, 00:36 | |
| Todd Ransom | Apr 27, 00:38 | |
| Marco Scheurer | Apr 27, 01:03 | |
| Dan Treiman | Apr 27, 01:40 | |
| Ondra Cada | Apr 27, 01:47 |






Cocoa mail archive

