Skip to content
DiaGO

Information Expert

Assign a responsibility to the class that has the information needed to fulfil it. GRASP's first and most-used principle.

The question GRASP answers

GRASP — General Responsibility Assignment Software Patterns, catalogued by Craig Larman — is a set of nine patterns that answer one question you face constantly in object-oriented design: which class should be responsible for this? Every method you write is an answer to that question, whether you thought about it or not. Objects combine state and behavior; GRASP is about deciding which object gets which behavior.

Information Expert is the pattern to try first. Its advice is short:

Assign a responsibility to the class that already has the information needed to fulfil it.

That is a heuristic, not a rule of UML or of any language. Nothing stops you from putting logic anywhere. The pattern exists because responsibility placement, more than anything else, determines how your design reacts to change.

Worked example: who computes an order total?

An Order holds a list of OrderLine objects. Each line knows its quantity and unit price. Someone has to compute the order total — where does that method go?

Ask who has the information. Computing a line's subtotal needs quantity and price: OrderLine has both. Computing the order total needs all the subtotals: Order has the lines. So each class computes the part it is expert on:

class OrderLine {
  constructor(
    readonly quantity: number,
    readonly unitPrice: number,
  ) {}
 
  subtotal(): number {
    return this.quantity * this.unitPrice;
  }
}
 
class Order {
  private lines: OrderLine[] = [];
 
  addLine(line: OrderLine): void {
    this.lines.push(line);
  }
 
  total(): number {
    return this.lines.reduce((sum, line) => sum + line.subtotal(), 0);
  }
}

Note the shape: the responsibility is distributed across partial experts. Order does not reach into lines to multiply quantities by prices; it asks each line for its subtotal and sums them. Collaboration between experts is the normal case, not an exception.

Contrast that with the design many codebases drift into:

class OrderTotalService {
  calculateTotal(order: Order): number {
    let total = 0;
    for (const line of order.getLines()) {
      total += line.getQuantity() * line.getUnitPrice();
    }
    return total;
  }
}

This is the smell known as feature envy: a class more interested in another class's data than its own. To make it work, Order must expose its internal line collection and OrderLine must expose every field. The pricing rule — quantity times price — now lives far from the data it describes. When per-line discounts arrive, you edit the service, and probably every other service that duplicated the loop. In the expert version you edit OrderLine.subtotal() and nothing else moves.

Expert versionOrderTotalService
CohesionPricing logic sits with pricing dataData in two classes, logic in a third
CouplingCallers depend on one method, total()Service depends on the internals of both classes
Change localityNew line-level rule -> edit OrderLine onlyChange ripples through getters and every consuming service

Why it works

The pattern buys you two things, and they are the same two forces behind most design advice:

  • Cohesion. Behavior sits next to the data it operates on, so a class reads as a coherent unit. This is the object-level cousin of the Single Responsibility Principle: the class changes for reasons related to what it knows.
  • Encapsulation, which lowers coupling. If the class with the data does the work, other classes never need the data. Fewer getters, fewer classes that break when a representation changes. If you sketch the design as a class diagram, the expert version simply has fewer dependency arrows.

The cost is that logic is spread across many small classes rather than gathered in one place you can read top to bottom. That trade is usually worth it, but it is a trade.

Where the pattern runs out

Some responsibilities have no natural information expert. Saving an Order to a database needs SQL and connection handling — information no domain class holds, and none should. Rendering an order on screen is the same. Force these onto the domain expert and you get a god class: an Order that knows pricing, persistence, HTML, and email formatting.

GRASP's escape hatch is Pure Fabrication: invent a class that corresponds to nothing in the domain — an OrderRepository, a ReceiptFormatter — purely to hold a cohesive technical responsibility. This is exactly the split that a layered architecture enforces at system scale. Information Expert is the default; Pure Fabrication is the deliberate exception you reach for when the default would damage cohesion.

Common mistakes

  • Anemic domain objects. Services that pull every field out through getters and do all the work, leaving domain classes as data bags. This is Information Expert inverted: the data holders are experts on nothing.
  • The hoarding expert. One class accumulating dozens of responsibilities because it "has the data". Holding the data qualifies a class as a candidate; it does not obligate it to do everything. Split by reason-for-change.
  • Ignoring coupling. Mechanically assigning to the data holder without checking what the assignment drags in. Expert answers who knows enough; you still have to check what it now depends on.

Reach for it

  • The responsibility reads or derives values from data one class already holds
  • You want a rule change to stay inside a single class
  • You are choosing between a domain object and a helper class for new logic

Avoid it

  • The responsibility is a technical concern such as persistence or rendering
  • Assigning it would couple the expert to unrelated subsystems
  • One class would hoard every responsibility just because it stores the data

Practice

A library lending system has Member, Loan, and Book. A Member holds its list of Loan objects; each Loan knows its dueDate, its returnDate (null while the book is out), and the borrowed Book; each Book knows its daily late fee. Add this responsibility: compute the total fine a member currently owes.

Using Information Expert, decide which class gets which method, write the three method signatures, and implement them in TypeScript or Java. Check your result: no class should expose a raw collection or field solely so another class can compute something from it. Then identify one responsibility in this domain — for example, persisting loans — that has no expert and would need a Pure Fabrication.