liveBook · Manning

Stateless system

As explained in Data-Oriented Programming: Reduce software complexity

A stateless function is a function whose result does not depend on persistent state stored inside the function or its containing module.

Suppose a Library module needs getBookLendings. Instead of hiding library state inside an object, pass LibraryData explicitly to a stateless function. The function operates on supplied data rather than persistent state stored in itself or its module. section 2.1 section 2.3

A stateless design separates the parts that hold information from the parts that manipulate it:

  • Data entities hold members but no code. section 2.4
  • Code modules aggregate functions without data members; each function receives the data it operates on explicitly. section 2.3
  • Unlike traditional object-oriented methods, these functions do not treat object state as an implicit argument. section 2.6
  • The separation makes the data and code easier to understand independently and supports flexible changes to requirements. section 2.4 section 2.6

Passing library state explicitly

class Library { static getBookLendings(libraryData, userId, memberId) { } } Here, libraryData is visible in the function signature rather than reached through this or another hidden object member. section 2.3

Figure 2.2 The separation between code and data

Use the diagram to see code modules and data entities as separate parts of one system. section 2.1

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines explicit data arguments and demonstrates module signatures, but defers deeper polymorphism discussion.
Examples
Uses a Library module and getBookLendings signature receiving LibraryData, userId, and memberId.
What it assumes
Builds from basic object-oriented method signatures and introduces the code-data separation without requiring functional-programming theory.
What you can do after
Apply it by designing modules whose functions receive manipulated data explicitly instead of reading encapsulated state.
How it connects
Ties stateless functions to data entities, code modules, object-oriented programming, and web-service data flows.

Also explained in

Compare how 14 books explain stateless system →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.