How to implement the Parcelable class?

1

I need help with the object-orientation issue.

I need to implement the Parcelable class in the Produto model, but for the sake of organization, I would not like to implement directly in the Produto class but to create a new ProdutoParcelable class and implement it there and make the class Produto identify this implementation or "develop" this implementation.

The detail is that in the possible class ProdutoParcelable I will need the attributes of class Produto .

public class Produto extends ProdutoParcelable

public class ProdutoParcelable implements Parcelable
//Aqui vou precisar dos atributos de Produto
    
asked by anonymous 02.06.2017 / 15:13

1 answer

1

In case of your problem, I would use a Product interface, where it would list the attributes of a product, and would create a class ProdutoModel and ProdutoParcelable , both implementing Product. So, when you were to create a normal product (without Parcelable) you would use Produto produto = new ProdutoModel(); . But I do not suggest you do two classes for this, you are increasing the complexity of understanding your code unnecessarily and it may be that in the future you wrap it up. Own experience.

On the implementation of Parcelable, go to this link that has a complete tutorial there.

    
07.06.2017 / 05:54