Java Interface/Implementation Model

In Java, all methods are virtual. This allows frameworks like Mockito to create unit-testing stubs from any class: MyFoo foo = Mockito.mock(MyFoo.class);

Temporal, however, requires that I declare an interface and an implementation for my activities and workflows.

Is this a hard requirement, or just an implementation detail? Could the Temporal java-sdk be written in a way as to require only annotating the implementation class/methods with @TemporalWorkfow, @WorkflowMethod, @QueryMethod, etc?

The same idea applies to python as well, which has even less of a concept of interfaces.

1 Like

I cannot comment on Python as I never wrote a line of production code in it.

Invocation of workflows and activities are essentially remote calls. So the framework needs a way to define APIs of workflows and activities in a clear way. Java interfaces were chosen for this specification.

Also I learned a hard way that forcing any framework that relies on dynamic code or bytecode manipulation on the users is not a good idea.

1 Like