Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What design pattern does Java Executor framework implements?

My understanding is that it seems very similar to Abstract Factory.

Note:

The executor interface:

public interface Executor {
     public void execute();
}

And then there is an Executors class containing static factories for various Executor implementations.

like image 249
rents Avatar asked Oct 14 '15 18:10

rents


1 Answers

It's not Abstract Factory. It is Mediator pattern coupled with Command pattern.

Executor interface is command pattern. Implementing execute() is obeying a Command.

According to GoF, Mediator pattern intent is:

Allows loose coupling by encapsulating the way disparate sets of objects interact and communicate with each other. Allows for the actions of each object set to vary independently of one another.

Mediator Pattern in JDK

java.util.Timer class scheduleXXX() methods

java.util.concurrent.Executor class execute() method.

java.lang.reflect.Method class invoke() method

Have a look source article for more details.

like image 50
Ravindra babu Avatar answered Nov 15 '22 07:11

Ravindra babu