3

In the semi-functional Java world, I see development methodologies that make heavy use of dependency injection and mocking frameworks to achieve high levels of unit test coverage. In order to achieve thread safety, behavior is encapsulated in objects which have no state and no side effects (except maybe writing to the logs). Sometimes I have seen this called an Anemic Domain Model and the objects called Behavior Objects.

Such a class is not intended to be inherited from, so it may be marked as final or sealed, and it has no super class, though it may implement an interface. A single instance of the object is meant to exist in memory at runtime and is shared across many threads.

I was wondering if there was a single word that could be used to describe such a class with no fields and only pure functions.

1
  • There are language specific names, such as "static class". Commented Oct 30, 2017 at 22:19

1 Answer 1

3

A class whose objects have no data member is a stateless class.

References:

  • oracle glossary : "A stateless object saves no application data; it is idempotent. Each operation on the object is independent of any other operations."
  • SO answer : "Stateless object is an instance of a class without instance fields (instance variables). The class may have fields, but they are compile-time constants (static final)."
  • Object-Oriented Design Decisions: Stateful or Stateless Classes? : In this blog the author makes the case for stateless helper classes.
4
  • Might be good to quote from both of the linked sources, in case the links go dead in the future. Commented Oct 28, 2017 at 18:30
  • @GregBurghardt good idea ! done ! Commented Oct 28, 2017 at 21:13
  • 1
    Stateless classes don’t require that their functions be pure... Commented Oct 28, 2017 at 21:17
  • @Telastyn It is fully true that a stateless class doesn't impose pure function. However, as the class is stateless, unless the functions use some global objects, interact with stateful parameters, or make some IO, the risk of the side effects are limited. Commented Oct 28, 2017 at 21:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.