---
# System prepended metadata

title: Stratified design

---

# Stratified design
* Understand **stratified design** and how it can help your team.
* Learn how to **extract functions** to make code cleaner.

## Definition:
Stratified design is a technique for building software in **layers**.

## Advantage:
1. flexible to change
2. Readable
3. Easy to test
4. Reusable

## The inputs to a stratified design sense
* Function bodies (Length/Complexity/Levels of detail/Functions called/Language features used) -> Detail
* Layer structure (Arrow length/**Cohesion**/Level of detail) -> Cohesion
* Function signatures (Function name/Argument names/Argument values/Return value) -> Name

## The outputs from a stratified design sense
* Organization (Decide where a new function goes./Move functions around.)
* Implementation (Change an implementation./Extract a function./Change a data structure.)
* Changes (Choose where new code is written./Decide what level of detail is appropriate.)

# Pattern 1: Straightforward implementations
## Visualizing function calls with a call graph
![](https://i.imgur.com/5GVSXHp.png)
![](https://i.imgur.com/X9t0tUw.png)

## Addingremove_item_by_name()to the graph
![](https://i.imgur.com/jm2Yv6D.png)
![](https://i.imgur.com/afC0gw4.png)

## All functions in a layer should serve the same pupose (Cohesion)
### Each of these layers is a different level of abstraction. That is, when you are working on functions in one layer, there are some common details that you don’t have to care about. 

## Three different zoom levels
1. Globalzoomlevel -> Interaction between layers
![](https://i.imgur.com/prMmEG5.png)
2. Layer zoom level -> Implementation of one layer
![](https://i.imgur.com/FFHtEdT.png)
3. Function zoom level -> Implementation of one function
![](https://i.imgur.com/mbqTVQl.png)

## At the layer zoom level, we compare arrows across functions
![](https://i.imgur.com/wyJauZJ.png)
![](https://i.imgur.com/FHwSxEH.png)
![](https://i.imgur.com/QL9vVY1.png)

## Summary

* Stratified design organizes code into layers of **abstraction**. Each layer helps us ignore different details.
* The **name** tells us the intent of the function. We can group it with other functions with related intents.
* The body can tell us the **details** that are important to a function. These are clues as to where in the layer structure it goes.
* We can improve the layer structure by extracting out more general functions. **More general functions are on lower layers and are more reusable.**
