Created
January 28, 2012 03:48
-
-
Save evanlong/1692489 to your computer and use it in GitHub Desktop.
partial class example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Started here | |
class Reader : NSObject {} | |
class PDFReader_Shared : Reader {} | |
class PDFReader_iPad : PDFReader_Shared {} | |
class PDFReader_iPhone : PDFReader_Shared {} | |
class TextReader_Shared : Reader {} | |
class TextReader_iPad : TextReader_Shared {} | |
class TextReader_iPhone : TextReader_Shared {} | |
///// | |
Now I want Reader to have iPad/iPhone specifics. In the WPF/Silverlight land I could solve this | |
with partial classes. To be fair it was all solved at compile time. Basically have 3 directores: | |
Shared, WPF, Silverlight. Then one build would do the partial classes of Shared+WPF and the | |
other was Shared+Silverlight. | |
For iOS this would need to be a runtime thing. Picking up the right Reader base class. | |
//// | |
class Reader_Shared : NSObject {} | |
class Reader_iPad : Reader_Shared {} | |
class Reader_iPhone : Reader_iPad {} | |
Now what would the PDFReader_Shared and TextReader_Shared derive from? It would need to be change | |
at runtime I guess which is scary (not sure if it's possible?) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could implement a class cluster. You’d only expose the
@interface
for the main class in the public header. The implementation file would look like this:If you don’t add any instance variables to
iPhoneClass
oriPadClass
, you can skip implementingalloc
, as their memory layout will be equivalent.