[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: splitting a class in pieces, compile-time dependent
From: |
David Chisnall |
Subject: |
Re: splitting a class in pieces, compile-time dependent |
Date: |
Tue, 23 Jul 2013 17:10:21 +0100 |
The approach I've used in the past is to have a common header that looks like
this:
@interface MyClass
/* Methods that are cross-platform */
@end
@interface MyClass (PlatformSpecific)
/* Methods that are platform-specific */
@end
Then, in the main .m file have:
@implementation MyClass
/* Methods that are cross-platform */
@end
#ifdef A
#include "A.m"
#elif defined(B)
#include "B.m"
#else
#error Unsupported configuration for MyClass
#endif
And in A.m and B.m have implementations of MyClass (PlatformSpecific).
David
On 23 Jul 2013, at 17:05, Riccardo Mottola <riccardo.mottola@libero.it> wrote:
>
> MyClass.m
>
> @implementation MyClass
>
> - (void)method
> {
> #ifdef A
> A stuff
> #else idfef B
> B stuff
> #endif
> }
> @end
>
> So I have conditional code, switched at compile time, which is just fine.
> However I have actually many more ifdefs (each representing an operating
> system) and the code got unreadable.
>
> I want to find a good way to split this in MyClass-A, MyClass-B, etc by
> adding the least possible logic and especially keeping everything static ad
> build time (not runtime).
>
> I thought of extending the class
>
> MyClass(A)
>
> -(void)methodA{}
>
> and then in the MyClass udate doing something:
> - (void)method
> {
> #ifdef A
> [self methodA];
> #else idfef B
> [self methodB]
> #endif
> }
>
> But hits is bogus: "MyClass" gets instantiated, nothing is known about
> methodA and thus an exception will be thrown.
>
>
> Can this method be refined? Or do you have different suggestions?
>
>
> Riccardo
>
> _______________________________________________
> Discuss-gnustep mailing list
> Discuss-gnustep@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
-- Send from my Jacquard Loom