Home

Awesome

Design patterns implemented in Scala

Inspired by Design patterns implemented in Java

Introduction

Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. The classical design patterns are the 23 design patterns by GoF.

This project implements dozens of design patterns in Scala. The Scala language has several advanced features which make the implementations are different from other programming languages.

Design patterns are categorized into:

  1. Creational
  2. Structural
  3. Behavioral
  4. Other
  5. Persistence

For each design pattern, it tags:

  1. scala features indicates if the implementation uses scala language-specific features.
  2. functional indicates if the design pattern can be implemented in functional-programming style.
  3. Gang of four indicates if the design pattern is one of the classical 23 design patterns by GoF

Creational

Namescala featuresfunctionalGang of four
abstract factorynonoyes
buildernonoyes
cakeyes(trait mix-in)nono
factory kitnoyesno
factory methodnonoyes
prototypenonoyes
simple factoryyes(companion object)nono
singletonyes(object)noyes
value objectyes(case class)nono

Structural

Namescala featuresfunctionalGang of four
adapteryes(implicit class)noyes
bridgenonoyes
compositenonoyes
decoratoryes(stackable trait)noyes
facadenonoyes
flyweightnonoyes
magnetyes(implicit conversion)nono
proxynonoyes
type classesyes(impilict parameter)nono

Behavioral

Namescala featuresfunctionalGang of four
chain of responsibilityyes(partial function)yesyes
commandnoyesyes
loanyes(structural type)yesno
mediatornonoyes
mementononoyes
observernonoyes
statenonoyes
strategynoyesyes
template methodnonoyes
visitornoyesyes

Other

Namescala featuresfunctionalGang of four
selfless traityes(companion trait)nono
monadnoyesno

Persistence

Namescala featuresfunctionalGang of four
data access objectnonono
repositorynonono

Getting Started

Run sbt assembly to compile, run tests and package all sub-projects.

If you want to operate specific sub-project, use project command in sbt shell to switch sub-project:

> projects          // list all sub-projects
> project builder   // switch to 'builder' sub-project
> project all       // switch to 'all' project which including all sub-projects

License

This project is licensed under the terms of the Apache 2.0 license.