Skip to content

Instantly share code, notes, and snippets.

@mike-pete
Last active February 28, 2023 23:54
Show Gist options
  • Save mike-pete/f7eab0d773fec4d08cf3c7959c90c21a to your computer and use it in GitHub Desktop.
Save mike-pete/f7eab0d773fec4d08cf3c7959c90c21a to your computer and use it in GitHub Desktop.
Design Patterns

Terms

Composition

  • Delegate work to helper objects.
  • Use objects from different concrete classes to get different implementations for helper methods.
  • strategy, state, etc.

Aggregation

  • (from refactoring.guru) object A contains objects B; B can live without A.

Inheritance vs Aggregation

Composition

  • (from refactoring.guru) object A consists of objects B; A manages life cycle of B; B can’t live without A.

Patterns

Behavioral Patterns

  • State
  • Strategy

Structural Patterns:

  • Decorator

Decorator

Structural

Wrapper objects that adds additional functionality to objects placed within.

State

Behavioral

Pretty much the Strategies pattern, except the helper objects can know about each other and can transition into other helper objects.

Strategy

Behavioral

The helper function loads the gun, the client hands the gun to the context, and the context pulls the trigger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment