6

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.

1
  • One thing to note though a factory is mostly concerned with creation , while the Executor interface defines a method that is mostly concerned with execution of tasks.
    – rents
    Oct 14, 2015 at 18:30

1 Answer 1

6

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.

3
  • The Command pattern is exhibited by the Runnable which is executed, rather than the Executor itself.
    – jaco0646
    Oct 15, 2015 at 2:32
  • Thanks for the link. But its more command pattern than mediator isn't it? not really sure what behavior/component is following mediator design pattern, can you help explain?
    – rents
    Oct 15, 2015 at 18:00
  • Have a look at :github.com/mryndzionek/java_mediator to understand in better way Oct 20, 2015 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.