Applying Domain Driven Design - Model/Implementation
I'm quite new in the DDD-World and I'm just trying to figure out all the basics so please bear with me! I have the following Entities: - Datamodel - Object Types - Object Fields A datamodel can contain 1..* object types and each object type has a unique name and can contain 1..* object fields. A field has a certain type which is either string, int, date OR it is an relational type: type User { name: String age: Int articles: Article } type Article { name: String author: User } Now I have the folowing use cases: Add a object-type to the datamodel Remove a object-type from the datamodel Add the object-field to the object-type Remove the object-field from the content-type As far as I understood, all of my entities build the aggregate and the Datamodel entity is the root entity, is that correct? I came along with the following implementation approach: The Datamodel entity has the ability to add object-types and holds a list of object-types: public class Datamodel { private final List objectTypes = new ArrayList(); public void addObjectType(String name) { ObjectType objectType = new ObjectType(name); this.objectTypes.add(objectType); } } The Object-Type entity has the ability to add object-fields and holds a list of object-fields. public class ObjectType { private final String name; private final List fields = new ArrayList(); public ObjectType(String name) { this.name = name; } public void addField(Field field) { fields.add(Objects.requireNonNull(field)); } } If I now want to add a relational field to my object type, I need to ensure, that the datamodel contains an object type with the respective name, thus I need access to the list of object types within the datamodel entity. How would I model this scenario? Is that approach correct or should the Datamodel entity be responsible for adding both object-types and object-fields?
I'm quite new in the DDD-World and I'm just trying to figure out all the basics so please bear with me!
I have the following Entities: - Datamodel - Object Types - Object Fields
A datamodel can contain 1..* object types and each object type has a unique name and can contain 1..* object fields. A field has a certain type which is either string, int, date OR it is an relational type:
type User {
name: String
age: Int
articles: Article
}
type Article {
name: String
author: User
}
Now I have the folowing use cases:
- Add a object-type to the datamodel
- Remove a object-type from the datamodel
- Add the object-field to the object-type
- Remove the object-field from the content-type
As far as I understood, all of my entities build the aggregate and the Datamodel entity is the root entity, is that correct?
I came along with the following implementation approach:
The Datamodel entity has the ability to add object-types and holds a list of object-types:
public class Datamodel {
private final List objectTypes = new ArrayList<>();
public void addObjectType(String name) {
ObjectType objectType = new ObjectType(name);
this.objectTypes.add(objectType);
}
}
The Object-Type entity has the ability to add object-fields and holds a list of object-fields.
public class ObjectType {
private final String name;
private final List fields = new ArrayList<>();
public ObjectType(String name) {
this.name = name;
}
public void addField(Field field) {
fields.add(Objects.requireNonNull(field));
}
}
If I now want to add a relational field to my object type, I need to ensure, that the datamodel contains an object type with the respective name, thus I need access to the list of object types within the datamodel entity. How would I model this scenario?
Is that approach correct or should the Datamodel entity be responsible for adding both object-types and object-fields?