I've been playing around with DCI after following along with The Right Way to Code DCI in Ruby. I find that I keep wanting my roles to add properties to my data objects.
For instance, if I have a user object.
class User
def initialize(name)
@name = name
end
end
user = User.new('JonMR')
The user may play the role of a customer.
module Customer
def add_to_cart(item)
self.cart << item
end
end
customer = user.extend Customer
customer.add_to_cart 'an item'
To make this work I need to add a cart method. Does the shopping cart really belong in the user object? It feels like the role should add the cart to the data object as needed.