2 Layers of abstraction

 

This chapter covers

  • How to break a problem down into subproblems with clean layers of abstraction
  • How layers of abstraction can help us achieve a number of the pillars of code quality
  • APIs and implementation details
  • How to break code into distinct layers of abstraction using functions, classes, and interfaces

Writing code is about solving problems. These can be high-level problems, such as “We need a feature to allow users to share photos,” all the way down to low-level problems such as “We need some code to add two numbers together.” Even if we’re not conscious of the fact we’re doing it, when we solve a high-level problem, we usually do it by breaking it down into multiple, smaller subproblems. A problem statement such as “We need a system to allow users to share photos” might imply that we need to solve subproblems like storing photos, associating them with users, and displaying them.

How we solve problems and subproblems is important, but often just as important is how we structure the code that solves them. For example, should we just dump everything into one giant function or class, or should we try and break it out into multiple functions or classes? And if so, how should we do this?

2.1 Nulls and the pseudocode convention in this book

2.2 Why create layers of abstraction?

2.2.1 Layers of abstraction and the pillars of code quality

2.3 Layers of code

2.3.1 APIs and implementation details

2.3.2 Functions

2.3.3 Classes

2.3.4 Interfaces

2.3.5 When layers get too thin

2.4 What about microservices?

Summary