dimanche 2 avril 2017

Difference between Execute Around Method and Template Pattern

I was trying to implement some of the GoF design patterns using Java 8 Lambdas. During this exercise, I came across the Execute Around Method (EAM) pattern and the Template Pattern. Both seem to have striking similarities.

I have read that the EAM is more of an idiom without inheritance and most examples seem to be around handling resources(open, doSomething,close) as compared to the Template pattern which uses inheritance.

On reading further, I see that EAM seems to have history in Smalltalk.

However, using Java 8 Lambdas, we can actually get rid of the inheritance in the Template Pattern and simply pass behavior. The solution to implement EAM idiom is very similar to Template design pattern. One could view the open,doSomething,close as a Template pattern too, open() and close() being the same steps but doSomething() being subclassed. Using Java 8 Lambdas , we could simply pass the behavior of doSomething to a function which accepts a java.util.function.Consumer. This can be seen both as a EAM and as a Template pattern.

So my question is what is the difference between the two ?

Aucun commentaire:

Enregistrer un commentaire