Sobes.tech
Senior

What is DCI?

sobes.tech AI

Answer from AI

DCI (Data-Context-Interaction) is an architectural pattern that divides a system into three main parts:

  • Data: Objects representing domain entities (e.g., User, Account). They contain state but are unaware of business logic.
  • Context: Gathers necessary data and associates it with roles in a specific transaction. The context knows which objects play which roles.
  • Interaction: Roles that define the business logic performed on data within the context. Specific actions that can be performed on data in a given situation.

DCI focuses on how real people think about object interactions in a specific scenario, rather than just on the structural organization of data. It aims to make business logic more explicit and easily readable.

Example: Money transfer between accounts.

  • Data: Account (state: balance)
  • Context: "Money transfer" that links two Account objects with roles "Source" and "Recipient".
  • Interaction: Roles "Source" (method withdraw) and "Recipient" (method deposit). Business logic: check for funds, change balances.

Main advantages of DCI:

  • Improved code readability: Business logic becomes more expressive and easier to track.
  • Better domain understanding: The pattern reflects real interactions between objects.
  • Increased flexibility: New interactions can be added without modifying existing data objects.
  • Reduced complexity: Focuses on short, isolated transactions.

DCI can be implemented with various programming languages, although some languages are better suited for its support (e.g., Scala with traits).