I learned this book from this website - refactoring guru, soon I bought the book after reading a couple chapters. I knew design pattern is important but I didn't really spend time on it. I know a couple but I didn't apply them correctly/precisely.

After reading the book, I actually got some inspirations and I'm going to read it partially and occassionally.

There are many patterns in the book and I'm not going to iterate them here, which doesn't make sense. I'm going to talk a couple patterns that I think is the most frequently used and important for those who work in industrials. As a review of what I've learned too.

Template Pattern

When I worked in Facebook, this is the pattern I've seen the most. Many business logics share a large overlap and differ at certain steps. The core idea is to override such certain steps to change the behavior of a method. Then I realized test runner is a very practical example (in case I violate NDA :P):

abstract class TestRunner:
  def pre_setup:
    pass

  def setup:
    pass
  
  def run_test:
    pass
  
  def tear_down:
    pass

  ...

When test runner runs, it executes certain steps, and usually we change our test setup by overriding the setup method, that's how it can fit into the whole process and making it very smart that the test can run according to our "settings".

Strategy Pattern

This is a new pattern to me. The core idea is to provide a high level goal as the interface, then provide different approaches implementing it, such approaches are called strategy. After learning this I suddenly understand the code written in the app, I understand why it's called "strategy manager" now. My takeaway is for such kind of code, just focus on what it can achieve, but don't spend too much time tracking each strategy, unless you work directly on it.

Command Pattern

It is very similar with strategy, but it is more like a series of steps for one strategy, I need revisit this one.

Mediator Pattern

I kind get the pattern but I didn't know its name. The book used a very nice example: the traffic controller of the airport. Every aircraft communicates with the traffic controller instead of each other, by doing this we can land UFO or a rocket, it doesn't matter! I was really happy to read this as I have the weapon to deal with similar problems now, which are usually coordinating the relationships among many differnt classes.

Postscript

This is really a nice book. I tried to learn design patterns systematically on w3 school, but it didn't work well for me. The terminologies and code examples keep confuse me. However, I found myself read this book so quickly and I really enjoyed it, so I highly reacommend you to read it too.