Scala Design Patterns
eBook - ePub

Scala Design Patterns

Ivan Nikolov

Share book
  1. 382 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Scala Design Patterns

Ivan Nikolov

Book details
Book preview
Table of contents
Citations

About This Book

Write efficient, clean, and reusable code with Scala

About This Book

  • 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

Who This Book Is 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

In Detail

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.

Style and approach

The design patterns in the book will be explained using real-world, step-by-step examples. For each design pattern, there will be hints about when to use it and when to look for something more suitable. This book can also be used as a practical guide, showing you how to leverage design patterns effectively.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Scala Design Patterns an online PDF/ePUB?
Yes, you can access Scala Design Patterns by Ivan Nikolov in PDF and/or ePUB format, as well as other popular books in Computer Science & Object Oriented Programming. We have over one million books available in our catalogue for you to explore.

Information

Year
2016
ISBN
9781785882500
Edition
1

Scala Design Patterns


Table of Contents

Scala Design Patterns
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. The Design Patterns Out There and Setting Up Your Environment
Design patterns
Scala and design patterns
The need for design patterns and their benefits
Design pattern categories
Creational design patterns
The abstract factory design pattern
The factory method design pattern
The lazy initialization design pattern
The singleton design pattern
The object pool design pattern
The builder design pattern
The prototype design pattern
Structural design patterns
The adapter design pattern
The decorator design pattern
The bridge design pattern
The composite design pattern
The facade design pattern
The flyweight design pattern
The proxy design pattern
Behavioral design patterns
The value object design pattern
The null object design pattern
The strategy design pattern
The command design pattern
The chain of responsibility design pattern
The interpreter design pattern
The iterator design pattern
The mediator design pattern
The memento design pattern
The observer design pattern
The state design pattern
The template method design pattern
The visitor design pattern
Functional design patterns
Monoids
Monads
Functors
Scala-specific design patterns
The lens design pattern
The cake design pattern
Pimp my library
Stackable traits
The type class design pattern
Lazy evaluation
Partial functions
Implicit injection
Duck typing
Memoization
How to choose a design pattern
Setting up the development environment
Installing Scala
Scala IDEs
Dependency management
SBT
Maven
SBT versus Maven
Summary
2. Traits and Mixin Compositions
Traits
Traits as interfaces
Mixing in traits with variables
Traits as classes
Extending classes
Extending traits
Mixin compositions
Mixing traits in
Composing
Composing simple traits
Composing complex traits
Composing with self types
Clashing traits
Same signatures and return types traits
Same signatures and different return types traits
Same signatures and return types mixins
Same signatures and different return types mixins
Multiple inheritance
The diamond problem
The limitations
Linearization
Rules of inheritance hierarchies
Linearization rules
How linearization works
Initialization
Method overriding
Testing traits
Using a class
Mixing the trait in
Mixing into the test class
Mixing into the test cases
Running the tests
Traits versus classes
Summary
3. Unification
Functions and classes
Functions as classes
Function literals
Functions without syntactic sugar
Increased expressivity
Algebraic data types and class hierarchies
ADTs
Sum ADTs
Product ADTs
Hybrid ADTs
The unification
Pattern matching
Pattern matching with values
Pattern matching for product ADTs
Modules and objects
Using modules
Summary
4. Abstract and Self Types
Abstract types
Generics
Abstract types
Generics versus abstract types
Usage advice
Polymorphism
Subtype polymorphism
Parametric polymorphism
Ad hoc polymorphism
Adding functions for multiple types
Self types
Using self types
Requiring multiple components
Conflicting components
Self types and the cake design pattern
Self types versus inheritance
Inheritance leaks functionality
Summary
5. Aspect-Oriented Programming and Components
Aspect-oriented programming
Chapter case example
Without AOP
With AOP
Components in Scala
Scala is rich
Implementing components
Self types for components
Summary
6. Creational Design Patterns
What are creational design patterns?
The factory method design pattern
Class diagram
Code example
Scala alternatives
What is it good for?
What is it not so good for?
The abstract factory
Class diagram
Code example
Scala alternatives
What is it good for?
What is it not so good for?
Other factory design patterns
The static factory
The simple factory
Factory combinations
Lazy initialization
Class diagram
Code example
What is it good for?
What is it not so good for?
The singleton design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The builder design pattern
Class diagram
Code example
Java-like implementation
Implementation with a case class
Using generalized type constraints
Changing the Person class
Changing the PersonBuilder class
Adding generalized type constraints to the required methods
Using the type-safe builder
Using require statements
What is it good for?
What is it not so good for?
The prototype design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
Summary
7. Structural Design Patterns
What are structural design patterns?
The adapter design pattern
Class diagram
Code example
The adapter design pattern with final classes
The adapter design pattern the Scala way
What is it good for?
What is it not so good for?
The decorator design pattern
Class diagram
Code example
The decorator design pattern the Scala way
What is it good for?
What is it not so good for?
The bridge design pattern
Class diagram
Code example
The bridge design pattern the Scala way
What is it good for?
What is it not so good for?
The composite design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The facade design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The flyweight design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The proxy design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
Summary
8. Behavioral Design Patterns – Part 1
What are behavioral design patterns?
The value object design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The null object design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The strategy design pattern
Class diagram
Code example
The strategy design pattern the Scala way
The command design pattern
Class diagram
Code example
The command design pattern the Scala way
What is it good for?
What is it not so good for?
The chain of responsibility design pattern
Class diagram
Code example
The chain of responsibility design pattern the Scala way
What is it good for?
What is it not so good for?
The interpreter design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
Summary
9. Behavioral Design Patterns – Part 2
The iterator design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The mediator design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
The memento design pattern
Class diagram
Code example
What is it good for?
What is it not so good for?
...

Table of contents