In an application, you have a requirement to fetch data and display it in multiple formats (list, grid, carousel). Which pattern can help you achieve this without duplicating the data-fetching logic?
- Adapter Pattern
- Bridge Pattern
- Observer Pattern
- Strategy Pattern
The Strategy Pattern is the most suitable for this scenario. It allows you to define a family of algorithms, encapsulate each one, and make them interchangeable. In this context, you can have different strategies for data presentation (list, grid, carousel), all sharing the same data-fetching logic. This pattern avoids code duplication while allowing flexibility in how data is displayed. The other patterns are not primarily intended for this purpose.
Loading...
Related Quiz
- What is the primary mechanism to pass data from a parent to a child component in React?
- What is a common naming convention for HOCs in the React community?
- When building a cross-platform app with React Native, what's a common challenge developers face related to platform-specific behaviors?
- Which React-Redux hook can be used to dispatch an action to the Redux store?
- How can you stop an event from propagating to parent elements in React?