I am trying to develop a data model for a very diverse set of interconnected objects. As the application matures, the types of objects supported will increase significantly. I want to avoid having to modify the model/schema whenever new object types are added.
As a simple example, let's say I'm starting with a model of people and buildings. A building can have multiple owners; a person can own multiple buildings; a person can live in a house and work in an office... Future versions might add cars and corporations. Cars can have owners, corporations can manufacture cars, people can work for corporations, etc. Most of the relationships will be many-to-many, some will be one-to-many, very few will be one-to-one.
While concepts like "owner", "employer", or "manufacture" can be considered properties of a "building", "corporation", or "car" object, I don't want to redefine the data model to support a new property type.
My current idea is to model this similar to a graph, where each piece of data is its own node. The node object would be very simple:
- Unique identifier
- Name (human representation)
- Node type
- Relationships
Extending the previous example, the possible node types would be:
- Person
- Car
- Company
- Building
A relationship would be:
- Node A
- Node B
- Relationship type - uses, owns, has, is, etc
I have a few questions:
- Are there any drawbacks to this approach?
- Is there an existing pattern or model that describes this?
- Are there better approaches?