nerdexam
Adobe

AD0-E724 · Question #33

A developer needs to programmatically create a URL rewrite for a custom entity page. Which service contract (repository) should be used to save the 'UrlRewrite' object?

The correct answer is C. 'Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface'. Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface is correct because Magento's service contract pattern dictates that you always depend on interfaces, not concrete implementations - this ensures your code is decoupled, testable, and upgrade-safe. Option A (UrlRewriteSavingInte

Customization

Question

A developer needs to programmatically create a URL rewrite for a custom entity page. Which service contract (repository) should be used to save the 'UrlRewrite' object?

Options

  • A'Magento\UrlRewrite\Api\UrlRewriteSavingInterface'
  • B'Magento\UrlRewrite\Model\UrlRewriteRepository'
  • C'Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface'
  • D'Magento\UrlRewrite\Model\ResourceModel\UrlRewrite'

How the community answered

(41 responses)
  • A
    12% (5)
  • B
    7% (3)
  • C
    78% (32)
  • D
    2% (1)

Explanation

Magento\UrlRewrite\Api\UrlRewriteRepositoryInterface is correct because Magento's service contract pattern dictates that you always depend on interfaces, not concrete implementations - this ensures your code is decoupled, testable, and upgrade-safe. Option A (UrlRewriteSavingInterface) does not exist in Magento's codebase, making it a fabricated distractor. Option B (UrlRewriteRepository) is the concrete class that implements the interface, but coding against a concrete model violates the service contract principle and tightly couples your code to the implementation. Option D (ResourceModel\UrlRewrite) is a lower-level persistence layer class, not a repository service contract, and should never be used directly in custom business logic.

Memory tip: In Magento, always reach for the *Interface in the Api\ namespace - if you see a class without Interface in its name or outside Api\, it's almost certainly the wrong choice for a service contract question.

Topics

#URL rewrite#service contract#UrlRewriteRepositoryInterface#repository interface

Community Discussion

No community discussion yet for this question.

Full AD0-E724 Practice