6

I'm creating a custom module, and I want to know if it's better to create a module with this structure :

Api/Data/CustomInterface.php
Model/Custom.php
Model/ResourceModel/Custom.php
Model/ResourceModel/Custom/Collection.php

My model implements the interface, and I create every getters and setters inside.

The other solution is this structure :

Model/Custom.php
Model/ResourceModel/Custom.php
Model/ResourceModel/Custom/Collection.php

No interfaces, no getters, no setters, few methods like Magento 1.

The first is slower, but cleaner. The second is faster, but messier.

Which is the best for you ?

Thank you

1 Answer 1

5

With service contracts usage (API interfaces), it will be possible to expose custom module functionality as web API just by adding config etc/webapi.xml. Improved capabilities for integration with 3rd party systems based on service contracts will be added in the future, as well as queue support.

Another benefit, if there is another module dependent on your module, it can just rely on service interfaces. This reduces coupling between modules and minimizes risk of accidental breaking of dependent module.

2
  • So for a simple module in which I declare some models, but I don't want any API support, what is the best ? Commented Dec 11, 2015 at 13:40
  • Recommended way is using service contracts, but it is up to you how to implement it in this case. Just make sure to use core service contracts in your module, not core models directly. Commented Dec 11, 2015 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.