[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Heads Up: ABI Change
From: |
Quentin Mathé |
Subject: |
Re: Heads Up: ABI Change |
Date: |
Sat, 12 Feb 2011 13:59:10 +0100 |
Le 12 févr. 2011 à 09:11, Richard Frith-Macdonald a écrit :
> On 11 Feb 2011, at 23:50, Stefan Bidi wrote:
>
>> On Fri, Feb 11, 2011 at 5:42 PM, David Chisnall <address@hidden> wrote:
>> Hi Stefan,
>>
>> I've not looked at the code in detail, but I thought you were creating a
>> private subclass for the old and new behaviours - would it not be possible
>> to simply return a private subclass instance from the constructors and not
>> change the ivar layout of the superclass?
>>
>> I really haven't got a clue how to go about getting something like that
>> done. I'm still at the "getting my feet wet" stage of OOP + ObjC. I'll
>> have a look at how NSString and it's subclasses are implemented, but I'll
>> probably need someone holding my hand, at least part of the way.
>
> The idea of using a subclass sounds good, and it's quite easy.
> I wouldn't recommend looking at NSString as an example though ... that's a
> much, much more complex case than would be needed.
>
> The simple subclassing solution would be to keep the old implementation in
> the base class, and just modify the +allocWithZone: method.
> eg.
>
> + (id) allocWithZone: (NSZone*z)
> {
> if (using_new_api && [NSDateFormatter class] == self)
> {
> // If the subclass calls the super implementation, the check for the
> class will prevent recursion.
> return [subclass allocWithZone: z];
> }
> else
> {
> return [super allocWithZone: z];
> }
> }
The problem I see with this approach is that you can change the formatter
behavior at runtime with -setFormatterBehavior:.
May be the class cluster approach is still a valid one, if it's possible to use
isa swizzling. e.g. Two subclasses NSDateFormatterBehavior10_0 and
NSDateFormatterBehavior10_4 with the same ivars (or instance size), and
-setFormatterBehavior implemented as below:
-setFormatterBehavior:
{
// NOTE: I haven't taken in account the default behavior case.
if (behavior == NSDateFormatterBehavior10_0)
{
behaviorClass = [NSDateFormatterBehavior10_0 class];
}
else if (behavior == NSDateFormatterBehavior10_4)
{
behaviorClass = [NSDateFormatterBehavior10_4 class];
}
objc_setClass(self, behaviorClass);
}
Cheers,
Quentin.
- Heads Up: ABI Change, David Chisnall, 2011/02/10
- Re: Heads Up: ABI Change, Stefan Bidi, 2011/02/10
- Re: Heads Up: ABI Change, David Chisnall, 2011/02/10
- Re: Heads Up: ABI Change, Richard Frith-Macdonald, 2011/02/11
- Re: Heads Up: ABI Change, Stefan Bidi, 2011/02/11
- Re: Heads Up: ABI Change, David Chisnall, 2011/02/11
- Re: Heads Up: ABI Change, Stefan Bidi, 2011/02/11
- Re: Heads Up: ABI Change, Richard Frith-Macdonald, 2011/02/12
- Re: Heads Up: ABI Change,
Quentin Mathé <=
- Re: Heads Up: ABI Change, Stefan Bidi, 2011/02/13
- Re: Heads Up: ABI Change, Richard Frith-Macdonald, 2011/02/14
- Re: Heads Up: ABI Change, Stefan Bidi, 2011/02/14