liveBook · Manning

Code-data separation

As explained in Data-Oriented Programming: Reduce software complexity

An architectural technique that represents program behavior and program data as separate entities rather than mixing them in one class.

When a library system puts member information and member behavior in the same class, one class can accumulate many data and code relations. Splitting them creates two simpler parts: data entities that hold information and code modules that manipulate it. section 1.2.1 section 2.0

The technique places behavior in stateless functions whose data arrives explicitly as an argument, rather than hiding state inside an object’s methods. Data and code can then be designed and understood independently. section 2.0 section 2.6

Figure 2.1 DOP principle #1 summarized: Separate code from data.

Use the principle diagram to see the intended boundary between data entities and code modules. section 2.0

The separation simplifies a system through several constraints:

  • Data entities contain members but no code; their relationships use association and composition. section 2.4
  • Code modules aggregate stateless functions; their relationships use module usage rather than inheritance. section 2.4
  • Independent data and code parts can be understood in either order without tracing the other part’s details. section 1.2.1 section 2.4
  • Changing permissions or member categories often adds focused functions instead of expanding a class hierarchy. section 2.5

Library permissions without a growing hierarchy

A library operation can receive libraryData explicitly, ask UserManagement whether the user is a librarian or Super member, and delegate retrieval to Catalog.getBookLendings. Adding VIP access similarly adds UserManagement.isVIPMember and a Catalog operation, without changing the data entities. section 2.5

For business logic that manipulates collections, keep intent-focused logic separate from data manipulation utilities. Discover each utility’s convenient signature, write its unit test, describe its behavior plainly, then implement it. section 14.5 section 14.5

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines entities, relations, stateless functions, and extension examples, while deferring polymorphism to a later discussion.
Examples
Uses a library management system, member permissions, class diagrams, data mind maps, module diagrams, and JavaScript-style listings.
What it assumes
Assumes familiarity with classes and object-oriented relations while teaching stateless functions and explicit data arguments.
What you can do after
Apply the technique by passing manipulated data explicitly and extending behavior through focused module functions.
How it connects
Connects data entities with stateless functions, modules, association, composition, usage, inheritance, encapsulation, and polymorphism.

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.