I'm writing a system that has a number of objects with data in them. For example one object has a user name attribute, another has a date, another shopping cart item etc.
I'm making an object that generates a MD5 hash based on a concatenated string of these values. So for example
md5(username + date + special_number + cart_id).
The way I was going to do this was pass the md5_generator object to each other the other objects in turn allowing them to call an
add_x method (eg
add_username) on the generator to add their specific piece of data. This avoids pulling the data out of each object, which I want to avoid.
I'm wondering if this is the best idea or if there is some simpler OO pattern I'm missing?