OndrejKucera / knowledge_scala_design_patterns

Description of design patterns in Scala (OOP & FP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Knowledge - Scala Design Patterns

Note: Here are not exhausted knowledge about patterns.

Design patterns are a well-described solution to the most commonly encountered problems which occur during software development and represents the best practices evolved over a period of time by experienced software developers. They promote reusability which leads to a more robust and maintainable code.

Replacing Object-Oriented Patterns with Functional Approach

1. Creational (gof)

  • Patterns create objects for you, rather than having you instantiate objects directly. This makes program more flexibility in deciding which objects need to be created for a given case.

2. Behavioral (gof)

3. Structural (gof)

  • Patterns show class and object composition. They use inheritance to compose interfaces and define ways to compose objects to obtain new functionality.

Functional Patterns

Functional programming has its own set of patterns that have evolved out of the functional style.

  1. Tail Recursion
  2. Mutual Recursion
  3. Filter-Map-Reduce
  4. Memoization - To cache the results of a pure function call to avoid performing the same computation more than once
  5. Lazy sequence - To create a sequence whose members are computed only when needed—this allows us to easily stream results from a computation and to work with infinitely long sequences
  6. Focused Mutability - To use mutable data structures in small, performance-sensitive parts of a program hidden inside of a function while still using immutable data throughout the majority

Anti-Patterns


The main resources were book Functional Programming Patterns in Scala and Clojure, the blog post from pavelfatin.com, and wikipedia page Design_Patterns

About

Description of design patterns in Scala (OOP & FP)