4

According to dev document there are no setter methods in data interfaces.

but in application almost every data interface contain setters also. There is no clarity on data interfaces.

According wikipedia an immutable object is an object whose state cannot be modified after it is created. So what objects comes under the category of immutable?

I hope some one will update devdocs properly.

If any one has some knowledge on above things can you give some examples?

It's really tough to understand all new patterns in magento2. Someone should share their knowledge in devdocs otherwise every one fears to see the code.

1 Answer 1

4

The devdocument is out of date and will need to be updated.

It is true that in the past the Service Layer and then the Service Contracts were implemented using a strategy of immutable data objects. Looking at the github history you can see that the strategy changed in early 2015 to allow data objects to be mutable.

As part of that change the builders that were needed for the immutable data objects were removed and it is recommended to use a factory instead. There is also now a DataObjectHelper to assist in creating or manipulating data objects via their interfaces.

You can find examples of usages in Carts.php and in CurrentCustomer.php

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.