5

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

3

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.

  • So for a simple module in which I declare some models, but I don't want any API support, what is the best ? – Maxime Huran Dec 11 '15 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. – Alex Paliarush Dec 11 '15 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.