Programming Abstractions

Abstraction is a technique that allows a programmer to make code more general and generic in order to solve a set of problems that share a recurring pattern but aren’t exactly the same.

For example, consider software that manages the inventory of a department store. You could write code that knows how to work with pricing and ordering information for shoes and then write very similar code for wallets. Alternatively, you could write more generic (abstract) code that works with “inventory items”.

An abstract solution would contain less code (and therefore the possibility for fewer bugs) but could also make it harder to understand the code. This is because there would no longer be any mention of specific items like shoes and wallets. You would also have to coerce shoes and wallets to act in similar ways with regards to inventory management.

The opposite of abstract is concrete.

Related Posts