9 Stratified design: Part 2

 
Image

In this chapter

  • Learn to construct abstraction barriers to modularize code.
  • Discover what to look for in a good interface (and how to find it).
  • Know when design is good enough.
  • Discover how stratified design helps maintenance, testing, and reuse.

In the last chapter, we learned how to draw call graphs and look for layers to help us organize our code. In this chapter, we continue deepening our understanding of stratified design and honing our design intuition with three more patterns. These patterns help us with the maintenance, testing, and reuse of our code.

Patterns of stratified design

Just as a reminder, we are looking at the practice of stratified design through the lenses of four patterns. We already covered pattern 1 in the last chapter. Because we’ve already got the fundamentals down, in this chapter we will cover the remaining three. Here they are again for reference.

Patterns

  • Image Straightforward implementations
  • Image Abstraction barrier
  • Image Minimal interface
  • Image Comfortable layers

this chapter will cover the remaining three

Pattern 1: Straightforward implementation

The layer structure of stratified design should help us build straightforward implementations. When we read a function with a straightforward implementation, the problem the function signature presents should be solved at the right level of detail in the body. Too much detail is a code smell.

Pattern 2: Abstraction barrier

Pattern 2: Abstraction barrier

Abstraction barriers hide implementations

Ignoring details is symmetrical

Swapping the shopping cart’s data structure

Re-implementing the shopping cart as an object

The abstraction barrier lets us ignore details

When to use (and when not to use!) abstraction barriers

Pattern 2 Review: Abstraction barrier

Our code is more straightforward

Pattern 3: Minimal interface

Pattern 3 Review: Minimal interface

sitemap