dimanche 14 janvier 2018

Big disadvantage of Decorator pattern

So we all know about the good 'ol Decorator pattern, especially I couldn't find any cons as such over Internet. But there is one big one I could think of:

If your base class happens to be bulky(holds like 50 fields) and you decide to decorate it:

public class BulkyBaseClass {

    // 50 fields
    //...
}

class Decorator extends BulkyBaseClass{

    private BulkyBaseClass mBase;

    public Decorator(BulkyBaseClass bulkyBaseClass){
        this.mBase = bulkyBaseClass;
    }

    // Some overrides to decorate the composed base class
}

Then, can't we see here that most of the fields of the decorator itself are useless and we are really only interested in the fields of the class being decorated and that leads to a big memory footprint?

To me, that's a big disadvantage. Isn't it?

Aucun commentaire:

Enregistrer un commentaire