java - Best practice for Decorator design pattern -


in right place decorator design pattern shines, noticed in many applications few mistakes made while using decorator.

an exemple (using java.io) demonstrate problem bad using of decorator.

public outputstream foo(...){     return new bufferedoutputstream(...); } 

the problem method, return bufferedoutputstream outputstream, user may decorate again object bufferedoutputstream (he don't know method return buffered stream), here got double buffering free (worsing more performance nothing).

another exemple :

public void foo(outputstream os){     bufferedoutputstream bos = new bufferedoutputstream(is);     ... } 

here exemple, user may supply bufferedoutputstream foo decorate internal use, user may want increase performance providing buffered stream, in reality he's making more worse, not fault, don't know method inside (black box).

so can tell me best practices using decorator design pattern, not java.io general use decorator?


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -