Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dart Design Patterns

A study project implementing the classic GoF (Gang of Four) design patterns in modern Dart 3 with sound null safety.

Each pattern lives in its own folder under lib/, with focused unit tests under test/. The file bin/main.dart contains a runnable demo of every pattern.


Implemented patterns

Creational — lib/creational/

Pattern Folder Description
Singleton lib/creational/singleton Guarantees a single instance with a global access point.
Factory Method lib/creational/factory Creates currency objects based on a country, without exposing the instantiation logic.
Builder lib/creational/builder Step-by-step construction of a Pizza object with optional toppings.

Structural — lib/structural/

Pattern Folder Description
Adapter lib/structural/adapter Bridges a legacy LegacyPrinter to the modern ModernPrinter interface.
Bridge lib/structural/bridge Decouples a RemoteControl abstraction from TV/Radio implementations.
Decorator lib/structural/decorator Wraps ice creams with toppings, accumulating price dynamically.
Facade lib/structural/facade Hides the complexity of booting a computer (CPU + memory + hard drive) behind a single start().

Behavioral — lib/behavioral/

Pattern Folder Description
Command lib/behavioral/command Encapsulates light on/off requests as objects with undo support.
Chain of Responsibility lib/behavioral/chain_of_responsibility Routes authorization requests through a chain of role-based handlers.
Observer lib/behavioral/observer A singleton Subject (event bus) that notifies registered callbacks.
State lib/behavioral/state A media player whose play/pause behaviour changes with its state.
Strategy lib/behavioral/strategy Fighters with swappable kick/jump/punch behaviours.
Template Method lib/behavioral/template_method Skeleton for preparing hot beverages, with overridable steps and a hook.

Getting started

Requires the Dart 3 SDK (>=3.0.0).

# install dependencies
dart pub get

# run the demo (all patterns)
dart run

# run the full test suite
dart test

# static analysis
dart analyze

Project structure

dart_design_patterns/
├── bin/
│   └── main.dart                      # runnable demo of every pattern
├── lib/
│   ├── creational/                    # ── Creational patterns ──
│   │   ├── builder/                       # Builder
│   │   ├── factory/                       # Factory Method
│   │   └── singleton/                     # Singleton
│   ├── structural/                    # ── Structural patterns ──
│   │   ├── adapter/                       # Adapter
│   │   ├── bridge/                        # Bridge
│   │   ├── decorator/                     # Decorator
│   │   └── facade/                        # Facade
│   └── behavioral/                    # ── Behavioral patterns ──
│       ├── chain_of_responsibility/       # Chain of Responsibility
│       ├── command/                       # Command
│       ├── observer/                      # Observer / Subject
│       ├── state/                         # State
│       ├── strategy/                      # Strategy
│       └── template_method/               # Template Method
└── test/                              # unit tests (one file per pattern)

Conventions

  • Dart 3 with sound null safety (sdk: '>=3.0.0 <4.0.0').
  • File names follow snake_case.dart.
  • Linting via package:lints recommended rules.
  • Tests use package:test.

License

Released under the MIT License.

About

Project for study design patterns in Dart.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages