Which pattern would you use in the following situation: You have a collection class that offers the ability to filter the collection, but since there are so many properties we could filter on, we want to maintain flexibility and not hard-code what property we filter on; rather we want to allow client code to specify what to filter on. 1) State 2) Strategy 3) Observer
Question 6
Which pattern would you use in the following situation: You have a collection class that offers the ability to filter the collection, but since there are so many properties we could filter on, we want to maintain flexibility and not hard-code what property we filter on; rather we want to allow client code to specify what to filter on.
1) State
2) Strategy
3) Observer
Which pattern would you use in the following situation: You have multiple components that need to react to events in their own way, and you have components that do not care about these events.
1) Observer
2) Strategy
3) State
Strategy pattern is used to encapsulate the algorithm inside the class. That means it puts each of them into separate class and make their objects interchangeable. In the given question, We want to focus on flexibility rather than client code to specify the filter. so, here Strategy pattern is used.
Step by step
Solved in 2 steps