Re: Core Data Subentities and Subclasses
Re: Core Data Subentities and Subclasses
- Subject: Re: Core Data Subentities and Subclasses
- From: Miguel Sanchez <email@hidden>
- Date: Mon, 16 Jan 2006 14:21:01 -0800
Q3. Is it "bad style" to have entity inheritance structured
differently to class inheritance?
the examples you point out in your first two questions deal with
simple key value coding.
within your code, the power of using inheritance is better realized
when reusing "business logic" implementations, that is, methods that
do more than simple KVC So as your custom classes get more
sophisticated, you probably will want the inheritance hierarchy to
reflect your model's.
- Miguel
On Jan 9, 2006, at 6:29 PM, Jonathon Mah wrote:
Hi all,
I'm having trouble understanding the relationship between Core Data
entity inheritance and class inheritance. I couldn't find any
documentation about it (on ADC or the list archives), so I did some
investigating and thought I should share the results.
For example, let's say there are four entities. (For clarity,
entities will be named EThing, and classes CThing.) ECar and ETruck
have EVehicle as their parent entity. EFerrari has ECar as its
parent entity.
EVehicle
(name, color)
/ \
ECar ETruck
(topGear) (wheelCount)
|
EFerrari
(topSpeed)
Now, EVehicle has its class set to CVehicle, a direct subclass of
NSManagedObject. I put together some questions and knocked up a
test app to try them out. Some I have answered myself.
Q1. Must ECar and ETruck's classes be a kind of CVehicle?
A1. No. It can be NSManagedObject, or a direct subclass of
NSManagedObject (e.g. CCar, or even CVehicle).
Q2. If ECar has its class set to NSManagedObject and I change its
name, will that call the -setName: method of CVehicle?
A2. No. It will only do so if ECar's class is set to a kind of
CVehicle.
Q3. Is it "bad style" to have entity inheritance structured
differently to class inheritance?
Jonathon Mah
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden