liveBook · Manning

Dependency

As explained in Data-Oriented Programming in Java

A dependency is a relationship in which one software element relies on another element's data, behavior, or availability.

A dependency is a relationship in which one software element relies on another element’s data, behavior, or availability. In a domain workflow, dependencies may be entities, databases, APIs, services, or environmental values. The design problem is not eliminating dependencies, but keeping their retrieval concerns from obscuring the work the application claims to perform. section 5.5.1

A draft builder with too many dependencies

A method named buildDraft may read the current date, call a contracts API, query a fee repository, inspect a customer database, and perform other lookups before constructing a draft. Its implementation then spends more effort managing data acquisition than building the draft itself. Separating those concerns makes the method’s domain behavior easier to read and trust. section 5.5.1

Analyze dependencies explicitly before deciding how to combine them:

  • Record what each operation reads or writes, including databases, APIs, entities, environment values, and outputs from earlier operations. section 5.5.1
  • Keep the application’s semantic data and core decisions distinct from the mechanisms that retrieve or submit them. section 5.5.1
  • Expect dependencies to influence design: a repository may know that primary-key lookup is fast while scanning is flexible but slow. section 10.4.7
  • Create wrappers deliberately when they add a semantic application boundary; avoid merely repackaging an underlying API. section 10.7
Listing 5.42 Analyzing the dependencies of our methods
collectPastDue
    DependsOn: 
        List<Invoice> (Entity / Database (read))
        CurrentDate (Environment (read))
        CustomerRating (API (read))
    Output: 
        List<PastDueInvoice>
 
buildDraft
    DependsOn:
        List<PastDue> (Output from collectPastDue)
        CurrentDate (Environment (read))
        PaymentTerms (API (read)) 
        FeePercentage (Database (read))
        Customer (Database (read))
  Output:
        Latefee<Draft>
 
assessDraft
    DependsOn:
        LateFee<Draft> (Output from buildDraft) 
        Rules (Database (read))
        Customer (Database (read))
        ApprovalStatus (API (read))
    Output: 
        Billable 
        OR NeedsApproval
        OR NotBillable  
submitBill
    DependsOn: 
        Billable (output from AssessDraft)
        BillingService (API write)  
    Output: 
        BilledLateFee
        OR RejectedLateFee    
 
startApproval
    DependsOn: 
        NeedsApproval (output from AssessDraft)
        CustomerID (database (read))
        ApprovalsService (API read/write)

Maps each workflow operation to its dependencies, their read or write source, and its output, making hidden coupling visible. section 5.5.1

Integration tests expose whether real dependencies behave as the application expects. Unlike mocked unit tests, they exercise interactions with systems outside the code’s direct control, such as database guarantees and access patterns. Their difficulty comes from needing a mental model of several systems at once. section 12.1

How Data-Oriented Programming in Java covers it

How deep it goes
Traces dependencies through inputs, outputs, read/write sources, wrappers, and integration tests rather than treating them as simple object references.
Examples
Uses draft building, invoice assessment, billing submission, database access, and task storage as dependency examples.
What you can do after
Evaluate dependency behavior by mapping interactions and exercising real databases or services through integration tests.
How it connects
Connects dependencies with data-oriented architecture, repositories, APIs, databases, wrappers, mocks, unit testing, and integration testing.

Also explained in

Compare how 35 books explain dependency →

Related concepts

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