Skip to main content
deleted 305 characters in body; edited title
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45

In an OO domain Domain model, what object is responsible for managing associations that do not required the behaviour of the associated object. How to model?

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs any behaviour of the other object i.e. the supplier object does not need to use any behaviour of the othercustomer object, yet there and visa versa.

There is however still this 'association'an association between them. The reason is that the problem domain requires that all a suppliers customers are destroyed if the supplier is destroyed. We also need to be able to retrieve a collection of all customers associated with a supplier.

How is itthis managed in the OO domain model? Who is responsible for the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new objecttype of class which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relatecould be used to model the association are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id) etc

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the usersupplier should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

Why would we then bother to add the responsibility of association to an object thats doesn't use it? Its useless to the object. The association isn't useless though, I just feel something else should be responsible for it.

In an OO domain model, what object is responsible for managing associations?

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. How is it managed in the domain? Who is responsible for the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the user should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

Why would we then bother to add the responsibility of association to an object thats doesn't use it? Its useless to the object. The association isn't useless though, I just feel something else should be responsible for it.

Domain model associations that do not required the behaviour of the associated object. How to model?

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs any behaviour of the other object i.e. the supplier object does not need to use any behaviour of the customer object and visa versa.

There is however still an association between them. The reason is that the problem domain requires that all a suppliers customers are destroyed if the supplier is destroyed. We also need to be able to retrieve a collection of all customers associated with a supplier.

How is this managed in the OO domain model? Who is responsible for the association?

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new type of class which has an association to a supplier, we have to add a get method to the supplier.

One thing I think could be used to model the association are repositories (from Eric Evens Domain Driven Design book). I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id) etc

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the supplier should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

Why would we then bother to add the responsibility of association to an object thats doesn't use it? Its useless to the object. The association isn't useless though, I just feel something else should be responsible for it.

added 226 characters in body
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45

In an OO domain model, if an object doesn't use anotherwhat object where do someis responsible for managing associations come from?

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. Where does this type of association come from? HowHow is it managed in the domain? Who managesis responsible for the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the user should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

Why would we then bother to add the responsibility of association to an object thats doesn't use it? Its useless to the object. The association isn't useless though, I just feel something else should be responsible for it.

In an OO domain model, if an object doesn't use another object where do some associations come from?

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. Where does this type of association come from? How is it managed in the domain? Who manages the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the user should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

In an OO domain model, what object is responsible for managing associations?

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. How is it managed in the domain? Who is responsible for the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the user should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

Why would we then bother to add the responsibility of association to an object thats doesn't use it? Its useless to the object. The association isn't useless though, I just feel something else should be responsible for it.

added 33 characters in body
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. Where does this type of association come from? How is it managed in the domain? Who manages the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the user should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. Where does this type of association come from? How is it managed in the domain?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed).

I've been struggling with this question for a while.

I'm specifically thinking within the object orientated domain model.

Let's say I have two entities. A supplier and a customer. There is a relationship that a supplier can have many customers, and a customer (in this case) can only have one supplier.

The issue I have is that neither object needs to use the other object, yet there is still this 'association' between them. Where does this type of association come from? How is it managed in the domain? Who manages the association?

At the moment I am actually associating each customer object with a supplier_id. While this of course makes sense when persisting the object in a database, having the supplier_id on the actual object adds no benefit at all. In fact, I think its just plain wrong.

Some may say that there should be a getCustomers() method on the supplier object and this is where the association lies. I don't really like this as it makes it difficult to close the supplier class (violation of Open Closed Principle). Every time we create a new object which has an association to a supplier, we have to add a get method to the supplier.

Another way would be to add a getUser() method to the supplier. This fixes the OCP violation on the supplier class, but why would we ever need to getUser() from a customer? At the object level it just makes no sense to have the association.

One thing I think it may relate to are repositories (from Eric Evens Domain Driven Design book). Neither class needs to use the other class, but there are certainly instances where we would want to get all the customers that a supplier has. I guess it would be the Repository that then cares about this relationship? We could call selectCustomersFor(supplier_id)

Edit

The only reason I can see for having the association is for object retrieval criteria or object destruction (i.e. if user is destroyed, all customers will be destroyed). To me, it is not the responsibility of either object to retrieve or destroy itself. You could argue that the user should retrieve/destroy a customer, but this surely violates the Single Responsibility rule, and could also lead to Open Closed violation.

Tweeted twitter.com/#!/StackProgrammer/status/509034715362234369
added 185 characters in body
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45
Loading
deleted 60 characters in body
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45
Loading
minor spelling correction
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 310
Loading
edited title
Link
GWed
  • 3.3k
  • 6
  • 28
  • 45
Loading
deleted 20 characters in body
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45
Loading
Source Link
GWed
  • 3.3k
  • 6
  • 28
  • 45
Loading