What design pattern does Java Executor framework implements?
Asked Answered
T

1

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.

Tucket answered 14/10, 2015 at 18:25 Comment(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.Tucket
S
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.

Submicroscopic answered 14/10, 2015 at 19:25 Comment(3)
The Command pattern is exhibited by the Runnable which is executed, rather than the Executor itself.Yoho
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?Tucket
Have a look at :github.com/mryndzionek/java_mediator to understand in better waySubmicroscopic

© 2022 - 2024 — McMap. All rights reserved.