Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Scala Design Patterns

You're reading from   Scala Design Patterns Design modular, clean, and scalable applications by applying proven design patterns in Scala

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher Packt
ISBN-13 9781788471305
Length 396 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Ivan Nikolov Ivan Nikolov
Author Profile Icon Ivan Nikolov
Ivan Nikolov
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. The Design Patterns Out There and Setting Up Your Environment 2. Traits and Mixin Compositions FREE CHAPTER 3. Unification 4. Abstract and Self Types 5. Aspect-Oriented Programming and Components 6. Creational Design Patterns 7. Structural Design Patterns 8. Behavioral Design Patterns – Part One 9. Behavioral Design Patterns – Part Two 10. Functional Design Patterns – the Deep Theory 11. Applying What We Have Learned 12. Real-Life Applications 13. Other Books You May Enjoy

Traits versus classes

Traits could be similar, but also very different to classes. It could be hard for a developer to choose which one to use in various cases, but here we will try to provide some general guidelines that should help.

Use classes:

  • When a behavior is not going to be reused at all or in multiple places
  • When you plan to use your Scala code from another language, for example, if you are building a library that could be used in Java

Use traits:

  • When a behavior is going to be reused in multiple unrelated classes.
  • When you want to define interfaces and want to use them outside Scala, for example, Java. The reason is that the traits that do not have any implementations are compiled similar to interfaces.
You have been reading a chapter from
Scala Design Patterns - Second Edition
Published in: Apr 2018
Publisher: Packt
ISBN-13: 9781788471305
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime