Single level of abstraction

Yury Kaspiarovich
1 min readMay 31, 2017

--

Each method should be written on a single level of abstraction. The term best be described using this example:

Violation of “Single Level of Abstraction” rule

The add_attendee_with_details method here brakes the rule.

The fill_in(‘order_user_email’, :with => ‘test@gmail.com’) part is more detailed than the fill_order_form part, so the code inside the add_attendee_with_details written on a different level of abstraction.

Now consider this piece of code:

Obeying the “Single Method of Abstraction” rule

We introduced additional method fill_attendee_details which hides the details of filling the attendee information thus has a higher level of abstraction, the same as other method calls inside add_attendee_with_details.

Code written using this rule a lot easier to read and understand. I suggest everyone to use it.

Obey the “Single Level of Abstraction” rule

--

--