Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

scala - 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?

question from:https://stackoverflow.com/questions/3084546/design-patterns-for-functional-oo-hybrid-languages

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...