Model: 3 techniques for introducing types

February 2nd, 2021

 

 

(1) Technique: Breaking out

Splitting a Large Object into a Group of Collaborating Objects

when: object is becoming complex

why: object has multiple concerns (violates Single Responsibility)

 


 

(2) Technique: Budding off

Defining a New Service That an Object Needs and Adding a New Object to Provide It

(A) Value Types: placeholder type

introduce a placeholder type that

- wraps a single field,

or maybe

- has no fields at all

 

(B) Objects

discover new types by “pulling” them into existence

when: some new feature doesn’t belong

how:

  1. create interface ("from the object’s point of view")

  2. test while mocking interface to describe the relationship

“If this worked, who would know?”

 

If the right answer to that question is not in the target object,

it’s probably time to introduce a new collaborator.

 


 

(3) Technique: Bundling up

Hiding Related Objects into a Containing Object

(A) Value Types

group values that are always used together

why: missing construct

how:

  1. new type

  2. move fields into type

 

(B) Objects

goal: Heuristic: Composite Simpler Than the Sum of Its Parts

how:

  1. new type

  2. move fields into type (public access)

  3. move behaviour into type

  4. hide fields behind clean interface (aka Heuristic: Composite Simpler Than the Sum of Its Parts)

benefits:

 


 

(src: Book: Growing Object Oriented Software, Guided By Tests - Steve Freeman & Nat Pryce)