Abstract entities and inheritance in Core Data

后端 未结 1 1323
感情败类
感情败类 2021-01-17 09:49

I have a data model for Formula 1 races with 3 entities:

  • RacingActor: Abstract entity
  • Pilot: inherits from RacingActor
  • Team: inherits from Ra
相关标签:
1条回答
  • 2021-01-17 10:15

    Core Data at the core is an object relational mapping library. Long time ago it was called Entreprise Object Framework, part of WebObjects.

    So yes, the base object for any persistant object managed by Core Data is NSManagedObject, and you can do whatever you want with them.

    In your example, Team and Pilot will share a common table, and you'll be able to use queries to retrieve Teams and Pilots at once. That's the idea.

    The Objective-C inheritance tree (if you use custom classes) can mirror the model you defined, but it doesn't need to. You can create a custom RacingActor class, use it as a base class for custom Team and Pilot classes, or you can tell the model to use RacingActor for Team and Pilot objects. You can even define a completely unrelated base class (provided NSManagedObject is a parent, directly or indirectly) for Team and / or Pilot if you want to.

    You are then free to implement the specific behaviors you need in your business logic, either in controllers or in custom data classes.

    0 讨论(0)
提交回复
热议问题