Head First Design Patterns adapted for Dart

I've adapted the Java examples from the Head First Design Patterns book to Dart.

Setup

dart pub get

Patterns

Strategy pattern

Defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

dart run bin/strategy_pattern.dart

Observer pattern

Defines a one-to-many dependency between objects so that when an object changes state, all it's dependents are notified and updated automatically.

dart run bin/observer_pattern.dart

Decorator pattern

Attach additional responsibilities to an object dynamically. Decorator provides a flexible alternative to sub-classing for extending functionality.

dart run bin/decorator_pattern.dart

Factory pattern

The Factory Method pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method pattern lets a class defer instantiation to subclasses.

The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.

dart run bin/factory_pattern.dart

Singleton pattern

The Singleton pattern ensures a class has only an instance and provides a global point of access to it.

dart run bin/singleton_pattern.dart

Command pattern

Encapsulates a request as an object, thereby letting you parametrize clients with different requests, queue or log request, and support undo-able operations;

dart run bin/command_pattern.dart