I’m designing an object named ContactInfoEntity that has an NSString property, contactInfoEntityType, and a container object, properties, that stores an arbitrary number of properties based on it’s contactInfoEntityType.
The goal is for the user to be able to define a new ContactInfoEntityType during runtime.
Right now I’m using an NSMutableDictionary in ContactInfoEntityType that has a key:@”typeName” of value:@”Generic”.
To define a new ContactInfoEntityType, I change the value of the key:@”typeName” and add new keys: @”newPropertyName1″, @”newPropertyName2″,… with NSDicts as values. The keys of the nested dictionaries are something like: @”defaultValue”, @”index”, @”formatToken”, …
When [ContactInfoEntityFactory contactInfoEntityOfType:emailInfoEntityType]; is sent, the factory gets the NSMutableDictionary with @”emailInfoEntityType” as the value for it’s @”typeName” key and sees that there are three additional dictionary entries: @”domain”, @”localPart”, and @”emailNickname”.
It then creates a ContactInfoEntity whose contactInfoEntityType is @”emailInfoEntityType” and properties container has three entries with the associated defaultValues.
Right now my properties container is an NSArray and an NSMutableArray. The NSArray holds the newPropertyNames and the NSMutableArray holds the values – both at the same index. The NSArray does duplicate some of the information in the entity type definition, but I feel it keeps the data in the individual entities meaningful in case the definitions get wiped out.
Is this a reasonable approach to this problem? This is the most abstract object I’ve attempted so far and still haven’t wrapped my head around all the common design patterns.
Specifically, are there more appropriate classes to use than NSMutableDictionary for the type definition and NSArray/MutableArray for the properties object?
Any input on the way I posed the question is also appreciated.
The only thing that jumps out at me as being potentially annoying is:
I have a long-standing dislike of parallel arrays as a way of relating data elements. I’d recommend a single array of objects, with each object containing a name/value pair. It prevents some types of subscript errors and gives the opportunity for pair-specific logic if that’s ever needed.