Bird
0
0

You need to design a facade service that merges user profile data from UserService and application preferences from PreferencesService. Which implementation best follows the facade pattern?

hard📝 Conceptual Q8 of 15
Angular - Advanced Patterns

You need to design a facade service that merges user profile data from UserService and application preferences from PreferencesService. Which implementation best follows the facade pattern?

ACreate a facade service that exposes a combined observable using <code>combineLatest</code> from both services.
BInject both services into the component and merge data there instead of using a facade.
CExpose each service's observables separately without combining them in the facade.
DHave the facade service directly modify data inside <code>UserService</code> and <code>PreferencesService</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Understand facade responsibility

    The facade should abstract and combine data sources for the component.
  2. Step 2: Analyze options

    Create a facade service that exposes a combined observable using combineLatest from both services. uses combineLatest to merge observables, fitting the facade pattern.
  3. Step 3: Eliminate incorrect options

    Inject both services into the component and merge data there instead of using a facade. moves logic to component, breaking abstraction; C exposes raw observables; D violates service encapsulation.
  4. Final Answer:

    Create a facade service that exposes a combined observable using combineLatest from both services. -> Option A
  5. Quick Check:

    Facade should combine and abstract data streams. [OK]
Quick Trick: Use combineLatest to merge observables in facade [OK]
Common Mistakes:
  • Merging data in components instead of facade
  • Exposing raw service observables without abstraction
  • Modifying internal service data from facade

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes