I’m relatively new to Objective-C and I have an enum with a corresponding array of string descriptions:
typedef enum {
kCoverage = 0,
kSingulation,
kPopulation,
kDownforce,
} MapTileType;
static NSString* const kMapTileTypeString[] = {
[kCoverage] = @"Coverage",
[kSingulation] = @"Singulation",
[kPopulation] = @"Population",
[kDownforce] = @"Downforce",
};
I’m discovering that I actually need to define behavior for the “type” of map tile. For instance, I have a tile rendering behavior that applies to a specific type of map tile.
static RenderingStrategy* const kMapTileTypeRenderingStrategy[] = {
[kCoverage] = ...,
[kSingulation] = ...,
...
};
I’m wondering if all of this stuff would be better suited for a class definition for encapsulation purposes. Or would I just use a factory method that receives a MapTileType and returns a RenderingStrategy?
I was thinking that I could also perhaps just use a delegate:
@protocol MapTileDelegate <NSObject>
-(NSString*)description;
-(void)renderBlahBlah...;
@end
Can somebody help break my analysis paralysis? 🙂
Without knowing more, there are two approaches that sound like they might make sense:
Turn the MapTileTypes into subclasses of MapTile that implement the custom behavior you’re looking for.
Create a MapTileBehavior class or something along those lines and have instances of that class take the place of your MapTileTypes values.