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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *