2 Layers of abstraction

 

This chapter covers

  • How to break a problem down into subproblems using layers of abstraction
  • How to break code into distinct layers, and why this is important

Writing code is about solving problems. These can be high-level problems, like “we need a system to allow users to share photos,” all the way down to low-level problems like “we need some code to add two numbers together." As with many problems in life, there are usually multiple ways to solve them and just using the first solution that pops into your head without thinking things through runs the risk of causing more problems than you’re solving. This is not to say that the first thing that pops into your head will necessarily be a bad way of solving a problem. It might well be the best solution, but thinking it through rather than just assuming this will give you a clear set of reasons why. Even once you’ve decided on a solution, it’s still worth thinking about how you structure the code that implements that solution.

2.1   Nulls and the pseudocode convention in this book

2.2   Why use 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?

2.5   Summary