Audrey Li

Learning JavaScript, Swift, and more...

A Design Pattern Story in Swift – Chapter 11: State

Feature Image
HouseOfFlower is hosting a betting sale. People can use a blue diamond to start a bet. If they win the bet, they’ll get one flower. The “FlowerHouseContext” is trying to keep a record of the business by using the four states: NoDiamond, HasDiamond, Sold, Soldout.
Read more »

A Design Pattern Story in Swift – Chapter 10: Composite

Feature Image
There is a MagicConference and all kinds of characters can participate by purchasing SinglePass or GroupPass.
Read more »

A Design Pattern Story in Swift – Chapter 9: Iterator(Sequence and Generator)

Feature Image
There is a restaurant with two kinds of menus: one for their VIP guests and one for customers who just want average fastfood. The two menus are in different format and one waitress has to be able to process both menus, in a simple way.
Read more »

A Design Pattern Story in Swift – Chapter 8: Template

Feature Image
There is very little difference between magic and art. It’s an act to create something from nothing.
Read more »

A Design Pattern Story in Swift – Chapter 7: Adaptor & Facade

Feature Image
We all have our innermost dream. Sometimes it becomes true, sometimes it doesn’t. When you see the tears in my eyes, that’s because my dream is broken. Fate often has its own play. We never know for sure.
Read more »

A Design Pattern Story in Swift – Chapter 6: Command

Feature Image
If you command wisely, you’ll be obeyed cheerfully. — Thomas Fuller
Read more »

A Design Pattern Story in Swift – Chapter 5: Singleton

Feature Image
Long before the seven kingdoms were created, there was a pen – a pen that can write stories into realities. In the vast universe, there is only one pen of this kind.
Read more »

A Design Pattern Story in Swift – Chapter 4: Factory

Feature Image
We all have our special weapons. And we fight for what we believed in.
Read more »

A Design Pattern Story in Swift – Chapter 3: Decorator

Feature Image
There is a powerful sorcerer in town. He sells magic potions and only charges them for blue diamonds. Blue diamond is a special kind of currency in the magic world and people are born with certain amount of that. The sorcerer would give old customers or his favorite customers different discounts.
Read more »

Strategy Design Pattern Updated Using Protocol Extension in Swift 2.0

Feature Image
I came across the Protocol-Oriented programming concept recently and I found it quite fascinating, so I decided to rewrite my previous story with protocols and value-based approaches.
Read more »

A Design Pattern Story in Swift – Chapter 2: Observer

Feature Image
In the deep forest, there is a beautiful witch who was born with the power to tell the past and future. In the beginning she was just a little girl in a nearby village. She knows everyone and whenever she sees danger in the future, she would warn the person. But soon she realized there are simply too many people to warn, and some of which don’t even want any help.
Read more »

A Design Pattern Story in Swift- Chapter 1: Strategy

Feature Image
Once upon a time, there was a girl living happily in the deep forrest. She did not know where she came, nor where she is suppose to be. The only unfamiliar memory she had is that many years ago, before she could wake up from the cold and molded stone, she heard a distance whisper, saying “home, home, this is your home”.
Read more »