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:
For each design pattern, it tags:
- scala features indicates if the implementation uses scala language-specific features.
- functional indicates if the design pattern can be implemented in functional-programming style.
- Gang of four indicates if the design pattern is one of the classical 23 design patterns by GoF
Creational
Name | scala features | functional | Gang of four |
---|---|---|---|
abstract factory | no | no | yes |
builder | no | no | yes |
cake | yes(trait mix-in) | no | no |
factory kit | no | yes | no |
factory method | no | no | yes |
prototype | no | no | yes |
simple factory | yes(companion object) | no | no |
singleton | yes(object) | no | yes |
value object | yes(case class) | no | no |
Structural
Name | scala features | functional | Gang of four |
---|---|---|---|
adapter | yes(implicit class) | no | yes |
bridge | no | no | yes |
composite | no | no | yes |
decorator | yes(stackable trait) | no | yes |
facade | no | no | yes |
flyweight | no | no | yes |
magnet | yes(implicit conversion) | no | no |
proxy | no | no | yes |
type classes | yes(impilict parameter) | no | no |
Behavioral
Name | scala features | functional | Gang of four |
---|---|---|---|
chain of responsibility | yes(partial function) | yes | yes |
command | no | yes | yes |
loan | yes(structural type) | yes | no |
mediator | no | no | yes |
memento | no | no | yes |
observer | no | no | yes |
state | no | no | yes |
strategy | no | yes | yes |
template method | no | no | yes |
visitor | no | yes | yes |
Other
Name | scala features | functional | Gang of four |
---|---|---|---|
selfless trait | yes(companion trait) | no | no |
monad | no | yes | no |
Persistence
Name | scala features | functional | Gang of four |
---|---|---|---|
data access object | no | no | no |
repository | no | no | no |
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.