Re: is protected broken, or am I?
Re: is protected broken, or am I?
- Subject: Re: is protected broken, or am I?
- From: matt neuburg <email@hidden>
- Date: Thu, 10 Oct 2002 15:42:16 -0700
>
On 10/10/02 5:24 pm, "matt neuburg" <email@hidden> wrote:
>
> I don't want to put the code for this alternate behavior into MyClass. I'd
>
> like to put it into some other class and have an instance of that other class
>
> step into MyClass's coat, as it were, taking on all the outlets, and being
>
> pointed to by all the window stuff, that the MyClass instance already is set
>
> up with in the nib.
>
> This is why I thought of a subclass of MyClass. If there is a better
>
> architecture for accomplishing this, I'd be glad to hear it.
>
>
What you have said above is (as far as I understand) all to the good.
>
If you have an instance of MySubClass, it has full access to all the ivars
>
that were defined in MyClass.
>
>
But what you had previously written about was code where your instance of
>
MySubClass had a pointer to some other (who knows what it was) instance of
>
MyClass and you were trying to access ivars of that other instance.
>
Why did you introduce that other instance and what was it for?
Because it is that other instance that has the ivar *values* I want. - Look, here's a picture of my nib file:
MyClass<----------->window
(File's Owner)
There is a bunch of code in MyClass, and there are a lot of connections set up between the MyClass instance and the window in the nib (represented by the double-headed arrow). Now I have a bunch of *other* code that governs this *other* behavior of the *same* window. The question is, where shall I put this code?
I don't want to put it into MyClass because MyClass is already huge, and also because this will mean that just about every method in MyClass will be a huge if/then statement doing one thing on one set of occasions and another thing on another set of occasions.
That is just the sort of the problem that classes are supposed to solve. Instead of if/then, you just supply a different class, and the right thing happens because whichever class the message is sent to an instance of, it contains the right code.
But how can I slot that code into the above picture? Basically I want that code to be where MyClass's code is in the picture - with access to all those connections to the window. But I can't do that, because MyClass's code is already there, if you see what I mean. The File's Owner proxy already represents an instance, an instance of MyClass, which owns the nib.
So I thought of a subclass, also instantiated in the nib:
MyClass<----------->window
(File's Owner)
|
|
|
MySubClass
My idea was that I would connect the MySubClass instance to the MyClass instance, and then the MySubClass instance could see the window connections by way of the MyClass instance (because this is what I thought "protected" meant), and would also inherit the same functionality (because it's a subclass) and so would be able to keep what was applicable and override what was not.
The problem is that MySubClass does not, as I was hoping, inherit access to MyClass's ivars. So now I'm asking whether there's a better way to do this. m.
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
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.