Design principles

What are the design principles have in scala,what use it.

Does this chapter from Programming in Scala, First Edition answer your question?

sorry i didn’t get above you please anyone give me proper answer?

Sorry, I also didn’t get the proper question, so that was really the best I could do…

1 Like

Question: what are functional design principles in scala,like Singleton, Factory, Decorator, Dependency Injection …etc

Now I’m a lot more confused. Are you asking you those design patterns get implemented in Scala? I wouldn’t call those “principles”.

I’m really not sure what you’re asking – you may want to ask in more detail…

I am also a beginner but so far in my study of scala it appears that a lot of the design patterns that you find in Java are actually built into the scala language. Singleton, for instance, appears to take the form of the “object” in scala for the most part. Factory seems to be built in using the apply method in a companion object and appears to come automatically in case classes. All those nifty patterns you find in java seem to be implemented using high-order functions that take and return functions; e.g. visitor, decorator, strategy. I guess you can also directly implement those patterns in scala taking an empirical approach. I mean there probably is nothing stopping you from creating a standard java like singleton. Hey, you can use java directly in Scala if you like. One thing though, in Scala there is no static keyword. In java you usually use a static to implement some of the patterns. I notice that so far the books I have looked at in Scala do not seem to talk much about design patterns in the way they do in the java documentation.

In scala, instead of declaring a static variable in a class, you declare a field in the companion object.

1 Like

thank you sidhartha.