How to instantiate a model in Magento 2

- Magento 2

Magento 2 Development

Since Magento strictly discourages the use of ObjectManager, there are service classes for abstracting it for all scenarios. Thus, you should use factory for all models (non-injectables):

You only have to ask a desired model’s factory in a constructor. Hence, it will be automatically generated, while you run compiler or Magento.


More tips from Magento 2 Developer’s Cookbook

Source (Magento Stackexchange Question) (Marius)