AD0-E724 · Question #2
When programmatically creating a new entity type, a developer uses the repository pattern for data management. Which of the following are key benefits of using the Service Contract and repository patt
The correct answer is A. It promotes loose coupling, making the module more robust against core upgrades. B. It automatically generates REST and SOAP API endpoints for the entity. E. It abstracts the underlying data persistence logic, like EAV or flat tables.. Using Service Contracts (interfaces) and the repository pattern in Magento 2 provides genuine architectural benefits: A is correct because coding to interfaces rather than concrete implementations means third-party modules won't break when Magento's core changes its internals. B
Question
When programmatically creating a new entity type, a developer uses the repository pattern for data management. Which of the following are key benefits of using the Service Contract and repository pattern for entity manipulation? (Select all that apply.)
Options
- AIt promotes loose coupling, making the module more robust against core upgrades.
- BIt automatically generates REST and SOAP API endpoints for the entity.
- CIt bypasses all plugin and observer logic for faster execution.
- DIt allows direct write access to replica database connections for better performance.
- EIt abstracts the underlying data persistence logic, like EAV or flat tables.
How the community answered
(52 responses)- A73% (38)
- C12% (6)
- D15% (8)
Explanation
Using Service Contracts (interfaces) and the repository pattern in Magento 2 provides genuine architectural benefits: A is correct because coding to interfaces rather than concrete implementations means third-party modules won't break when Magento's core changes its internals. B is correct because Magento's web API framework automatically exposes properly annotated service contract interfaces as both REST and SOAP endpoints via webapi.xml, eliminating manual API wiring. E is correct because the repository pattern hides whether data is stored in EAV tables, flat tables, or any other mechanism - callers just use save()/getById() without caring about SQL details.
C is wrong because repositories still fire plugins and observers normally - they don't short-circuit the event/plugin system. D is wrong because replica (slave) database connections are read-only by design for replication safety; no pattern grants write access to them.
Memory tip: Think of Service Contracts as a "public menu" for your module - customers (other modules and APIs) order from the menu without seeing the kitchen (E), the menu is stable even if the kitchen is remodeled (A), and Magento automatically prints that menu in both REST and SOAP formats (B).
Topics
Community Discussion
No community discussion yet for this question.