I'm studying some ObjC source here and one of the controllers has a property of type NSDictionary
that is called "overrideClassNames
".
As key it wants the class of an existing interface and as value the class of a subclass of the existing one, like:
controller.overrideClassNames = @{(id)[DefaultType class] : [MySubClassedDefaultType class]};
Whenever an instance of DefaultType
is required, it would look up the dictionary and create a more specialized instance if one has been set.
I'm thinking if this is actually a common approach in ObjC? Coming from C# and Java, my idea would have been to create a delegate factory method that is called if an instance of DefaultType
is required. The user of the class could then return his more specialized version.
Alternatively (in C#) I would make the class generic and let it have a <T> : DefaultType, new()