# 9 - Stratified design Part 2 ## recap - Pattern 1: Straightforward implementation ![](https://i.imgur.com/rvKpSlp.jpg) ## Pattern 2: Abstraction barrier ### Abstraction barriers hide implementations ![](https://i.imgur.com/TWslAOh.jpg) ### Ignoring details is symmetrical marketing team => don't care the details of the implementation dev team => don't care how marketing team uses the functions ### Re-implementing the shopping cart as an object ...(略) ### The abstraction barrier lets us ignore details What lets us change the data structure without changing all of the code that uses shopping carts? > "Abstraction" is just a fancy way of saying, “What details can I ignore? ![](https://i.imgur.com/UnvYEwF.jpg) **Notice how there are no arrows that cross the dotted line.** ## When to use (and when not to use!) abstraction barriers ### To facilitate changes of implementation an abstraction barrier can be the layer of indirection that lets you change the implementation later ![](https://i.imgur.com/qfge6yj.jpg) **However, this benefit is often a trap** Abstraction barriers make change easy, but **that’s not why we should use them**. They should be used strategically to **reduce inter-team communication and help clarify messy code.** ### To make code easier to write and read Abstraction barriers allow us to ignore details. When writing code with lot of details, Did we initialize the loop variables correctly? Did we have an off-by-one error in the loop exit condition? Did we ... ### To reduce coordination between teams The abstraction barrier allows teams on either side to ignore the details the other team handles. ### To mentally focus on the problem at hand An abstraction barrier makes some details unimportant to the problem we are solving right now. ## Pattern 3: Minimal interface There are many reasons to keep the abstraction barrier minimal: 1. If we add more code to the barrier, we have more to change when we change the implementation. 2. Code in the barrier is lower level, so it’s more likely to contain bugs. 3. Low-level code is harder to understand. 4. More functions in an abstraction barrier mean more coordination between teams. 5. A larger interface to our abstraction barrier is harder to keep in your head. ## Pattern 4: Comfortable layers ## What does the graph show us about our code? ![](https://i.imgur.com/m22lmuh.jpg) 1. Maintainability—What code is easiest to change when requirements change? 2. Testability—What is most important to test? 3. Reusability—What functions are easier to reuse? ## Code at the top of the graph is easier to change ![](https://i.imgur.com/6srEdIg.jpg) ![](https://i.imgur.com/8CtHWM7.jpg) ## Testing code at the bottom is more important ![](https://i.imgur.com/yrXkNfQ.jpg) ![](https://i.imgur.com/bRLaUC6.jpg) answer ![](https://i.imgur.com/VBJQbik.jpg) ## Code at the bottom is more reusable ![](https://i.imgur.com/3hIwfX5.jpg) ## Summary: What the graph shows us about our code ![](https://i.imgur.com/4uwmQDG.jpg)