On May 18, 2005, at 12:19 PM, Raffael Cavallaro wrote:
On May 18, 2005, at 12:12 PM, Bill Bumgarner wrote: If you are mutating models on the fly and you aren't creating an application specifically chartered to be creating models, then your model does not sufficiently describe your application's data.
An application "specifically chartered to be creating models" is called a dynamic language runtime. The Objective-C runtime is not flexible enough to allow model modifications at runtime, since by design, Objective-C models are meant to be built using the Objective-C class system, and these classes can only be loaded but not unloaded at runtime.
Don't confuse (at least don't confuse others :-) data modeling with code modeling (classes, class hierarchy, etc.) or overly tie the two together [1]. You can model your data such that you can deal with changes in its structure (with in the limits of what your schema allows for) at runtime without requiring modification at runtime of the code (or bindings or the schema itself).
In fact NSManagedObject is in a way an example of one aspect of this since it can represent any arbitrary object in your applications object graph at runtime and it (obvious at the hands of the managed context) does so based on what your schema defines. Additionally dynamic modification of binding paths, etc. at runtime gives you additional abilities however good schema design can avoid having to do such things.
One way to think of it is that in your schema you should model not only your application data but also how its structure could be modified at runtime (just another piece of data to model). In other words don't add a property to an entity (aka column to a table) in your schema at runtime instead define your schema such that you can capture that additional data and relate it as needed (could be a simple as table that captures named or unnamed attributes that can be related to other objects in the schema).
Of course how flexible your schema is needs to balanced against how complex you want it and how likely schema changes are, etc. It isn't an exact science.
FYI it is known that the Apple's Objective-C runtime is getting closer to allowing for unloading of classes at runtime [2]. Also GC is being worked on for Apple's Objective-C runtime [3].
-Shawn
[1] Sure you could use a dynamic language runtime to also address this but you still have similar issues to deal with let alone how to persist the data in an format such that you can understand what it contains, etc.
|