gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re[6]: Recent key-value encoding changes to NSObject.


From: Manuel Guesdon
Subject: Re[6]: Recent key-value encoding changes to NSObject.
Date: Mon, 11 Feb 2002 19:17:23 +0100 (CET)

On Mon, 11 Feb 2002 17:48:43 +0000 Richard Frith-Macdonald <address@hidden> 
wrote:
 >| On Monday, February 11, 2002, at 04:01 PM, Manuel Guesdon wrote:
 >| 
 >| >
 >| > Take this hierarchy Class X derived from EOGenericRecord derived from 
 >| > NSObject
 >| > Say X will have 2 values: a and b.
 >| > o X will store A in an ivar (_a) the other is stored in EOGenericRecord 
 >| > in a dictionary "_values".
 >| >         _value is a special dictionary which know it's keys (including 
 >| > a even if it won't store it itself in
 >| > our case. There's a reason for this that I could explain if you 
 >| > want :-).
 >| >
 >| > X will have the following methods:
 >| >         -(id)a
 >| >         {
 >| >                 [self storedValueForKey:@"a"];
 >| >         }
 >| >         -(void)setA:(id)anA
 >| >         {
 >| >                 [self takeStoredValue:anA
 >| >                         ForKey:@"a"];
 >| >         }
 >| >         -(id)b
 >| >         {
 >| >                 [self storedValueForKey:@"a"];
 >| >         }
 >| >         -(void)setB:(id)aB
 >| >         {
 >| >                 [self takeStoredValue:aB
 >| >                         ForKey:@"b"];
 >| >         }
 >| >
 >| >
 >| >  [x valueForKey:@"a"] should return the ivar _a (not the dictioanry 
 >| > value for a)
 >| 
 >| Ok.  -valueForKey: calls -a, which calls -storedValueForKey: which 
 >| accesses _a
 >| 
 >| >  [x valueForKey:@"b"] should return the  dictionary value.
 >| 
 >| Ok.  -valueForKey: calls -b, which calls -storedValueForKey: which tries 
 >| to call -_b (doesn't exist),
 >| then tries to store into _b (doesn't exist) then calls -b ... recursion.
 >| 
 >| How to fix ...
 >| 
 >| Option 1 ... override -storedValueForKey: to behave as you want ...
 >| 
 >| a. try to call -_b, then try to access ivar, then your special code to 
 >| handle the dictionary etc.
 >| This does involve some code duplication ... but not very much and it's 
 >| pretty simple/obvious.

Yes, I simply have to copy storedValueForKey: from NSObject and put it in 
EOGenericRecord and replace my additions it it
by a direct call on dictionary. That was what I wanted to avoid: 2 methods 
which does near the same things (except
EOGenericRecord has additional dictionaty stored values). Code change in one of 
the 2 code may produce some strange
things which may make user crazy :-)


 >| Option 2 ... as I described before, modify a few standard methods 
 >| somewhat like this -
 >| 
 >| - (BOOL) respondsToSelector: (SEL)aSel
 >| {
 >|    BOOL result = [super respondsToSelector: aSel];
 >| 
 >|    if (result == NO && this_is_a_private_get_method(aSel))
 >|      return YES;
 >| 
 >|    return result;
 >| }
 >| 
 >| - (NSMethodSignature*) methodSignatureForSelector: (SEL)aSel
 >| {
 >|    NSMethodSignature        *sig = [super methodSignatureForSelector: aSel];
 >| 
 >|    if (sig == nil && this_is_a_private_get_method(aSel))
 >|      return signature_of_method;
 >| 
 >|    return imp;
 >| }
 >| 
 >| - (IMP) methodForSelector: (SEL)aSel
 >| {
 >|    IMP        imp = [super methodForSelector: aSel];
 >| 
 >|    if (imp == forwarding_method && this_is_a_private_get_method(aSel))
 >|      return get_method;
 >|    return imp;
 >| }
 >| 
 >| - (id) theGetMethod
 >| {
 >|    // examine _cmd and fetch the appropriate value from the dictionary.
 >| }

I'n not sure I follow your demonstration :-)
The  "theGetMethod" is my "x -(id)a" method  ?
If yes, this is not good since  "user" can't just put "|self 
storedValueForKey:@"..."] in it.


 >| I cant really see much point in doing it that way just to avoid a little
 >| code duplication.

I'm not talking about the the size of the duplicated code but about putting the 
same (a little complex) code in 2
different places. It's also about having to do so in others places if we need 
same feature for other objects.

But, if this little patch (just for memory, it 's only an intermediate call 
before really calling GSGetValue, GSSetValue
and GSInstanceVariableInfo) really annoy you I can put it in EOGenericRecord. 
Intellectually, I don't like that but I
don't like the idea of 3 people spending so much time on this :-(

Manuel

--
______________________________________________________________________
Manuel Guesdon - OXYMIUM <address@hidden>
14 rue Jean-Baptiste Clement  -  93200 Saint-Denis  -  France
Tel: +33 1 4940 0999  -  Fax: +33 1 4940 0998




reply via email to

[Prev in Thread] Current Thread [Next in Thread]