lundi 7 septembre 2020

Avoid having to override all methods in Decorator

I've been recently learning about design patterns and have a doubt with Decorator. For me it's pretty clear how useful it is to add extra functionality on a class method.

However, when dealing with a class that has multiple methods, all methods must be overriden even if not extended at all, ending with something like the following for each one of them:

@Override
public void whateverMethod() {
  decorated.whateverMethod();
}

Having to write this stuff for all methods (even if just two or three) seems quite unoptimal to me. Am I misunderstanding something? Is there another pattern to solve this?

Aucun commentaire:

Enregistrer un commentaire