I have been talking about the Information Expert GRASP Pattern as it pertains to my Create a Shopping Cart example.
I have been fixing the original code to remove code smells as well as make sure the Information Expert Principle is being followed. In this example, I am changing the following code as follows:
In the AddItem method above, the ArrayListCart class "makes a copy" of item before placing it in the _items ArrayList. As I mentioned in the Creat a Shopping Cart post, this is not ideal (bogus actually) as ArrayListCart is not the Information Expert on what it takes to make a copy of Item. Item is. Item should have a Copy() method to make a copy of itself.
Now we have a much cleaner solution that follows the Information Expert GRASP Pattern. Although you don't have to follow these principles as if they are written in stone, you can see that they may help show problems in your code. Check out Applying UML and Patterns for more information on GRASP Patterns.