Find Missing Abstractions

Learn about missing abstractions and duplication of structure.

We'll cover the following

Duplication of structure

Duplication of structure often means there’s a missing abstraction, which in Ruby generally means we can move some code into a new class.

One symptom is a set of instance attributes that are always used together, especially if the same group of attributes is being passed to multiple methods. The use of a common set of variables often indicates that we want a new class with those friendly attributes as the instance attributes.

Another common symptom is a group of methods that all share a prefix or a suffix, such as logger_init, logger_print, and logger_read. Often this means we need a class corresponding to the common word.

In ActiveRecord, one side effect of discovering friendly attributes is creating value objects, which are immutable instances that represent parts of our data. For example, a start_date and end_date are often used together and could easily be combined into a DateRange class. Also, how often do we write something like this?

Get hands-on with 1200+ tech skills courses.