AD0-E724 · Question #10
Which of the following statements about observers in Adobe Commerce are considered best practices? (Choose 2.)
The correct answer is A. Observers should be coded defensively and not assume specific data will always be present in the B. Observers should be designed to be lean and performant to avoid degrading the performance of. A is correct because events may be triggered in varying contexts where expected data objects or keys are absent - defensive coding (e.g., null checks before accessing $observer->getData(...)) prevents fatal errors and makes observers resilient across different code paths. B is co
Question
Which of the following statements about observers in Adobe Commerce are considered best practices? (Choose 2.)
Options
- AObservers should be coded defensively and not assume specific data will always be present in the
- BObservers should be designed to be lean and performant to avoid degrading the performance of
- CObservers should contain complex business logic and database write operations to keep
- DIt is a good practice for an observer to dispatch a new custom event.
- EAn observer's logic should be placed directly inside the 'execute' method without using
How the community answered
(21 responses)- A71% (15)
- C5% (1)
- D19% (4)
- E5% (1)
Explanation
A is correct because events may be triggered in varying contexts where expected data objects or keys are absent - defensive coding (e.g., null checks before accessing $observer->getData(...)) prevents fatal errors and makes observers resilient across different code paths.
B is correct because observers execute synchronously within the request lifecycle; a slow or resource-heavy observer blocks the entire request, directly degrading storefront or admin performance for every event dispatch.
C is wrong - complex business logic and database writes belong in dedicated service classes or models, not observers. Observers should delegate to those classes, keeping themselves thin and testable.
D is wrong - dispatching a new event inside an observer creates the risk of circular event chains or cascading side effects that are difficult to debug and maintain. Adobe's documentation explicitly cautions against this.
E is wrong - the execute method should delegate to injected helper/service classes rather than containing all logic inline; this improves readability, reusability, and unit testability.
Memory tip: Think of observers as traffic cops, not workers. They should quickly check conditions (A - verify what's there) and wave traffic through efficiently (B - stay fast), then hand off real work to others. A traffic cop who builds roads, radios other cops, or does paperwork at the intersection causes gridlock.
Topics
Community Discussion
No community discussion yet for this question.