When to use the Class pattern

The Class pattern, much like the Constructor pattern, is useful when you have a self-contained concept that fulfills the following criteria:

  • The concept is expressible as a noun
  • The concept requires construction
  • The concept will vary between instances of itself

Here are some examples of concepts that abide by these criteria and are hence reasonable to express via the Class pattern:

  • A database record (represents a piece of data and allows inquiry and manipulation)
  • A todo item component (represents a todo item and allows it to be rendered)
  • A binary tree (represents a binary-tree data structure)

Typically such cases will stick out quite obviously to you. If you're having trouble, consider the use cases of your abstraction and try to write some consumer code, that is, pseudo code that utilizes your abstraction. If it seems sensible and doesn't feel too awkward to use, then you've probably landed on a good pattern.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.160.181