I have a common scenario where I have an object (a) that logically affects another object (b), like a makes a note on b, or a marks b as disabled (usually a is a user object of the system and b is some kind of business object like a customer or an appointment).
In the past, the method was on the affected object like:
customer.Disable(user); // user is marking the customer as disabled
... but it doesn't read well (it appears backwards). The opposite:
user.Disable(customer);
... reads better, but there's something about it that I can't put my finger on that just doesn't seem right. The only other option is to have a static intermediary:
ThirdPartyClass.DisableCustomer(customer, user);
... but the domain objects end up becoming more like DTOs and I prefer the domain model approach because it makes more sense.
So the question is: which makes the most sense? Is there an option I haven't considered? Who actually owns an operation like this?
Edit
With the second option, the actionable objects in the system (users usually) end up becoming huge because the users of the system are the ones that pretty much do and affect everything.
UserCustomerController
? I'm kidding. Really. Just hold an instance of theCustomer
class and call theDisable()
method on it. If you need to stamp the transaction with the user that did it, your first option makes more sense, as the method is being called on the thing being disabled.