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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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

 
Question 7 

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

Expert Solution
Strategy pattern is used in this case

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. 

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education