Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design patterns for functional-OO hybrid languages?

Is there already any collection of best practices for languages like Scala?

I've found a work on design patterns for functional languages, Design patterns for functional strategic programming. There's GoF design patterns for OO languages. But are there any patterns for functional-OO hybrids? All I've seen is this list. What is known?

like image 332
George Avatar asked Jun 21 '10 12:06

George


People also ask

Are there design patterns for functional programming?

In object-oriented development, we are all familiar with design patterns such as the Strategy pattern and Decorator pattern, and design principles such as SOLID. The functional programming community has design patterns and principles as well.

Are decorators functional programming?

Decorators are wrapper functions that enhance the wrapped function. You don't change the original function behavior, instead you decorate it with new behavior, achieving extensability and composability.


2 Answers

Two patterns from Bill Venners; I think both are heavily used in ScalaTest:

Stackable Trait (similar in structure to the decorator pattern, except it involves decoration for the purpose of class composition instead of object composition).

Selfless Trait (allows library designers to provide services that their clients can access either through mixins or imports).

Type safe builder

Independently Extensible Solutions to the Expression Problem - just like the "Scalable Component Abstraction", it's not a pattern catalog, but it also deals with similar problems (e.g. the Visitor pattern)

Deprecating the Observer Pattern - an alternative to the Observer.

We can also consider the Scala emulation of Haskell type classes a design pattern. The first description (that I could find at least) is in Poor Man's Type Classes. Quite some blog entries are also available with this topic.

And I think I'm not completely wrong if I also mention the various monads. You can find a lot of resources dealing with them.

like image 63
Sandor Murakozi Avatar answered Sep 21 '22 04:09

Sandor Murakozi


While not directly a design pattern catalog itself, the paper "Scalable Component Abstractions" (Martin Odersky; Matthias Zenger) examines three building blocks for reusable components:

  • abstract type members,
  • explicit selftypes, and
  • modular mixin composition.

And it revisits several design pattern (publish/subscribe, subject/observer, Context/Component) to illustrate and understand what language constructs are essential to achieve systems of scalable and dynamic components.

like image 30
VonC Avatar answered Sep 23 '22 04:09

VonC