Ruby Monstas


Levels of Abstraction

Levels of Abstraction

In the RubyMonstas course we will learn about 3 levels of abstraction:

#ConceptDeals with...
1VariablesData
2MethodsBehaviour
3ClassesData + Behaviour

This slideset will show the first level of abstraction, variables.

Abstraction

"The psychological profiling [of a programmer] is mostly the ability to shift levels of abstraction, from low level to high level. To see something in the small and to see something in the large."
Donald Knuth - Computer Scientist Extraordinaire
(Source: Wikiquote)

Values

Before variables, we were only dealing with concrete values, such as:

7
"Hello"
3.1415926

Variables

With variables we've reached the first level of abstraction.

Instead of using concrete values, we can now use placeholders that stand in for those values:

number_of_continents = 7
greeting = "Hello"
pi = 3.1415926

Abstraction

Thus, abstraction allows us to step away from concrete things towards broader concepts.

It also allows us to give things names (such as the variable names here).

This gives us the tools to express more complex things.

Abstraction

Abstraction is about reusing code and showing intent:

puts [342.75, 108.20, 241.00, 632.15, 499.55].sum

vs.

monthly_expenses = [342.75, 108.20, 241.00, 632.15, 499.55]
puts monthly_expenses.sum

Levels of Abstraction

#ConceptDeals with...
1VariablesData
2MethodsBehaviour
3ClassesData + Behaviour

What questions do you have?