I have trouble understanding these two design patterns.
Can you please give me contextual information or an example so I can get a clear idea and be able to map the dif
Seems like the second graph is Visitor Pattern to me...Since for strategy pattern, the class contains data structure tends to be only one, no subclass(Or the subclass stays same behavior of this part). The strategy is for different operations on the same structure.
The visitor is like a one-night stand - you create it when you call the accept function and then they get separated and the visitor can be cleaned from the memory, it doesn't take any room for the class that use it.
The strategy is like a marriage - you create the object, it lives in the class that uses it, takes memory, has a room and makes itself a coffee in the morning :) . Of course they can get a divorce and switch to another class but that class would also live in its owner's context.
Hope it helps you remember :)
Their differences are :
Not sure what is gained from comparing two different things but compare Strategy to Visitor.
What is same about the two to make one look for their differences?
I'll try to make the shortest answer.
The two patterns complement one another: for instance, you could use a visitor to change the strategies on all the nodes of a graph.
If we look at the UML for these two patterns from the GoF book, we see they are nothing alike.
Visitor:
Strategy:
Some important differences stand out from the diagrams.
UML alone does not capture the different motivations driving these patterns.