Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Scala Design Patterns
Scala Design Patterns

Scala Design Patterns: Write efficient, clean, and reusable code with Scala

eBook
€8.99 €36.99
Paperback
€45.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Scala Design Patterns

Chapter 1. The Design Patterns Out There and Setting Up Your Environment

In the world of computer programming, there are multiple different ways to create a solution that does something. However, some might contemplate whether there is a correct way of achieving a specific task. The answer is yes; there is always a right way, but in software development, there are usually multiple ways to achieve a task. Some factors exist, which guide the programmer to the right solution, and depending on them, people tend to get the expected result. These factors could define many things—the actual language being used, algorithm, type of executable produced, output format, and the code structure. In this book, the language is already chosen for us—Scala. There are, however, a number of ways to use Scala, and we will be focusing on them—the design patterns.

In this chapter, we will explain what design patterns are and why they exist. We will go through the different types of design patterns that are out there. This book aims to provide useful examples to aid you in the learning process, and being able to run them easily is key. Hence, some points on how to set up a development environment properly will be given here. The top-level topics we will go through are as follows:

  • What is a design pattern and why do they exist?
  • The main types of design patterns and their features
  • Choosing the right design pattern
  • Setting up a development environment in real life

The last point doesn't have to do much with design patterns. However, it is always a good idea to build projects properly, as this makes it much easier to work in future.

Design patterns

Before delving into the Scala design patterns, we have to explain what they actually are, why they exist, and why it is worth being familiar with them.

Software is a broad subject, and there are innumerable examples of things people can do with it. At first glance, most of these things are completely different—games, websites, mobile phone applications, and specialized systems for different industries. There are, however, many similarities in how software is built. Many times, people have to deal with similar issues, no matter the type of software they create. For example, computer games as well as websites might need to access a database. And throughout time, by experience, developers learn how structuring their code differs for the various tasks that they perform.

A formal definition for design patterns will allow you to understand the value of using good practice in building elegant and efficient software.

Note

The formal definition for design patterns

A design pattern is a reusable solution to a recurring problem in software design. It is not a finished piece of code, but a template, which helps solving the particular problem or family of problems.

Design patterns are best practices, to which the software community has arrived over a period of time. They are supposed to help write efficient, readable, testable, and easily extendable code. In some cases, they can be a result of a programming language not being expressive enough to elegantly achieve a goal. This means that more feature-rich languages might not even need a design pattern, while others still do. Scala is one of those rich languages, and in some cases, it makes the use of some design patterns obsolete or simpler. We will see how exactly it does that in this book.

The lack or existence of a certain functionality within a programming language also makes it able to implement additional design patterns that others cannot. The opposite is also valid—it might not be able to implement things that others can.

Scala and design patterns

Scala is a hybrid language, which combines features from object-oriented and functional languages. This not only allows it to keep some of the well-known object-oriented design patterns relevant but also provides various other ways of exploiting its features to write code, which is clean, efficient, testable, and extendable all at the same time. The hybrid nature of the language also makes some of the traditional object-oriented design patterns obsolete, or possible, using other cleaner techniques.

The need for design patterns and their benefits

Everybody needs design patterns and should look into some before writing code. As we mentioned earlier, they help writing efficient, readable, extendable, and testable code. All these features are really important to companies in the industry.

Even though in some cases it is preferred to quickly write a prototype and get it out, it is more usually the case that a piece of software is supposed to evolve. Maybe you will have experience of extending some badly written code, but regardless, it is a challenging task and takes a really long time, and sometimes it feels that rewriting it would be easier. Moreover, this makes introducing bugs into the system much more likely.

Code readability is also something that should be appreciated. Of course, one could use a design pattern and still have their code hard to read, but generally, design patterns help. Big systems are usually worked on by many people, and everyone should be able to understand what exactly is going on. Also, people who join a team are able to integrate much more easily and quickly if they are working on a well-written piece of software.

Testability is something that prevents developers from introducing bugs when writing or extending code. In some cases, code could be created so badly that it is not even testable. Design patterns are supposed to eliminate these problems as well.

While efficiency is often connected to algorithms, design patterns could also affect it. A simple example could be an object, which takes a long time to instantiate, and instances are used in many places in an application, but could be made singleton instead. You will see more concrete examples in the later chapters of this book.

Left arrow icon Right arrow icon

Key benefits

  • • Unleash the power of Scala and apply it in the real world.
  • • Increase your efficiency by leveraging the power of Creational, Structural, Behavioural, and Functional design patterns.
  • • Build object oriented and functional applications quickly and effectively.

Description

Scala has become increasingly popular in many different IT sectors. The language is exceptionally feature-rich which helps developers write less code and get faster results. Design patterns make developer’s lives easier by helping them write great software that is easy to maintain, runs efficiently and is valuable to the company or people concerned. You will learn about the various features of Scala and be able to apply well-known, industry-proven design patterns in your work. The book starts off by focusing on some of the most interesting features of Scala while using practical real-world examples. We will also cover the popular "Gang of Four" design patterns and show you how to incorporate functional patterns effectively. By the end of this book, you will have enough knowledge and understanding to quickly assess problems and come up with elegant solutions.

Who is this book for?

If you want to increase your understanding of Scala and apply it to real-life application development, then this book is for you. We’ve also designed the book to be used as a quick reference guide while creating applications. Previous Scala programming knowledge is expected.

What you will learn

  • • Immerse yourself in industry-standard design patterns—structural, creational, and behavioral—to create extraordinary applications.
  • • Feel the power of traits and their application in Scala.
  • • Implement abstract and self types and build clean design patterns.
  • • Build complex entity relationships using structural design patterns.
  • • Create applications faster by applying functional design patterns.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 29, 2016
Length: 382 pages
Edition : 1st
Language : English
ISBN-13 : 9781785882500
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 29, 2016
Length: 382 pages
Edition : 1st
Language : English
ISBN-13 : 9781785882500
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 134.97
Scala Functional Programming Patterns
€41.99
Scala Design Patterns
€45.99
Scala for Data Science
€46.99
Total 134.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. The Design Patterns Out There and Setting Up Your Environment Chevron down icon Chevron up icon
2. Traits and Mixin Compositions Chevron down icon Chevron up icon
3. Unification Chevron down icon Chevron up icon
4. Abstract and Self Types Chevron down icon Chevron up icon
5. Aspect-Oriented Programming and Components Chevron down icon Chevron up icon
6. Creational Design Patterns Chevron down icon Chevron up icon
7. Structural Design Patterns Chevron down icon Chevron up icon
8. Behavioral Design Patterns – Part 1 Chevron down icon Chevron up icon
9. Behavioral Design Patterns – Part 2 Chevron down icon Chevron up icon
10. Functional Design Patterns – The Deep Theory Chevron down icon Chevron up icon
11. Functional Design Patterns – Applying What We Learned Chevron down icon Chevron up icon
12. Real-Life Applications Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(5 Ratings)
5 star 60%
4 star 20%
3 star 0%
2 star 20%
1 star 0%
Tomer Ben David Apr 01, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
OMG forget about all the other scala books read this one! What a lovely surprise! Enjoying reading this books, it's explaining things so concise and well. At first I thought this was only about design patterns but then I found it to be a great book about scala. I find his explanations so well- "What is important about monoids is that they give us the possibility to work with many different types of values in a common way"- "monads are structures that represent computations as sequence of steps"- "functors are things that can allow us to lift a function of type A => B to a function of the type F[A] => F[B]"- "the cake design pattern is the scala way to implement dependency injection"- "stackable traits is the scala way to implement the decorator design pattern"- "type class design pattern allows us to write generic code by defining a behaviour that must be supported by all members of a specific type class"and it goes on and on! just perils of clear explanations! what a lovely book.
Amazon Verified review Amazon
Abhishek Srivastava Jun 09, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I loved this book. I loved the initial part of the book which has a great coverage of traits. The book then moves to the GOF patterns (which were kind of known to me) but I loved the coverage of cake pattern and Scalaz.I highly recommend this book.
Amazon Verified review Amazon
Akram Ahmad Jan 16, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Wow, I must confess that I'm thoroughly impressed by the uniformness of excellence of fine book offers in its helpful coverage of diverse Scala topics. This is an excellent second or third book for somebody has spent time getting comfortable with learning and using Scala. As the author correctly notes, "Using Scala to its full potential, however, requires us to be familiar with not only the object-oriented features, but also with the functional ones". And he does a really good job of covering both features (OO and FP). Plus, having meaningful examples makes learning and understanding a more pleasant experience. To that end, the author has provided plenty of examples that you can map to real problems that you would potentially be solving. All in all, "Scala Design Patterns" will be a superb addition to your programming library!
Amazon Verified review Amazon
Paolo R. Jul 21, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I found the book a useful collection of best practises and techniques you normally gain over time and after months of study on various resources.Here you have all in one place, ready to consult if you're a novice or an experienced dev.Definitely recommended if you are an experienced Java dev and you're looking for how to do things in the right way, without wasting days in researching!
Amazon Verified review Amazon
Amazon Customer Jun 16, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I put 2 stars because the Kindle version is impossible to read. There is no format at all.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.