(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:
- create interface (“from the object’s point of view”)
- 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:
- new type
- move fields into type
(B) Objects goal: Heuristic: Composite Simpler Than the Sum of Its Parts how:
- new type
- move fields into type (public access)
- move behaviour into type
- hide fields behind clean interface (aka Heuristic: Composite Simpler Than the Sum of Its Parts)
benefits:
- Heuristic: Composite Simpler Than the Sum of Its Parts
- name
- scope dependencies
- precise unit testing
(src: Book: Growing Object Oriented Software, Guided By Tests - Steve Freeman & Nat Pryce)