Are there already approved patterns or best practices available for Scala which were really tested extensivelly for real world projects? I don't even know if users of pure functional languages are really concerned (or have to be concerned) about design patterns as much as it's the case for users of OO languages. But I guess he interesting mix of OO and functional programming in Scala gives the possibility to discover even new patterns or best practices. Anyway, I d'like to hear about already existing ones, too
Any design pattern can be implemented in Scala. Design patterns are not specific to a language, although the best ways of implementing them might depend on the particular constructs available within the language. In some languages, certain design patterns are not needed at all; because, the language has built in solutions to the common problems the pattern was meant to address.
For example, you would never need a common implementation of the Singleton design pattern in Scala; because, Scala does not lack the feature of guaranteeing that only one object of a class exists in memory. With Scala, the language itself supports a singleton concept through the use of the keyword "object". It would be somewhat silly to document the problem, and it's common solutions when the common solution is just to use the correct keyword in the language.
Think of this, there's no "print line" design pattern in most languages because most languages already provide a simple means of directing a line of text to the screen. But if you were programming in assembly, where no single command will do the job, then a design pattern for "print line" might become useful.
thanks for your input! Of course I know that it should be possible to use most patterns equally in programming languages which are different but have enough similarities to apply a specific pattern (if we're talking only about design patterns at the "code level"). But my question wasn't very precise As you may have guessed I'd be more interested in patterns which are more specific to Scala. Some ideas about patterns which should be handled differently in Scala would be interesting as well.
But it intersting enough that you pointed out that some patterns are just kind of workarounds for inconveniences of a particular programming language or not really necessary in other languages
The patterns we're used to in Java can be implemented in Scala with mostly fewer lines of code.
Edwin mentioned about Singleton. In another post I mentioned about decorator pattern using traits.
In addition to these common or Gang-of-four patterns, as you start working with Scala, you will find
yourself using some additional patterns that make use of function values (and closures). One example
is the execute-around-method pattern or a variation of it called the loan pattern. The idiomatic
differences will lead you to explore some different patterns than you're used to in Java.
In addition you may also want to look at the Smalltalk Design Patterns.
Some of the patterns that make use of function values can be used with Scala as well.
Refer to Kent Beck's book on Smalltalk Best Practice Patterns (you can find a list of
the patterns in the book with a quick search on the web).