Scala Goodness: Compound Types

Scala is ideally suited for programming in roles because it does features traits. Think of Traits like interfaces in Java with implementation code. Say you have a dog:

then this dog has two roles, Callable and Feedable. You can extract those into traits:

and combine them with your Dog:

This is the first Scala goodness. But you can also extend your Dog at calltime:

When you’ve developed Java for some time and adhere to the usage of interfaces for roles, you surely have tripped over the problem that one of your methods expects a parameter object to implement two interfaces (sometimes this is a sign that the method does too much) and you resorted to adding an object twice to the method signature:

The call with twice the dog really does look ugly. And you get into shallow water semantically. Does the method call the two methods on two objects? Shouldn’t it call them on one method after each other?

Update: As Daniel pointed out, in Java one can write:

In Scala the method can be expressed nicer with a compound type as the parameter type:

Scala glory!

49 thoughts on “Scala Goodness: Compound Types”

  1. Pingback: ????? ??
  2. Pingback: Akantor Webdesign
  3. Pingback: para kazanmak
  4. Pingback: ankara escort
  5. Pingback: joseph de saram
  6. Pingback: joseph de saram
  7. Pingback: rhodium
  8. Pingback: sfeerkachel
  9. Pingback: surrogacy services
  10. Pingback: M88
  11. Pingback: kimim ben
  12. Pingback: porno
  13. Pingback: foundation
  14. Pingback: Denver Uber Driver
  15. Pingback: papas lo valledor
  16. Pingback: ballsache
  17. Pingback: android apps
  18. Pingback: kid fights mom
  19. Pingback: m88vnbet.com
  20. Pingback: Skrota bilen
  21. Pingback: Bilskrot Göteborg
  22. Pingback: brook stagles
  23. Pingback: Serrurerie Creteil
  24. Pingback: Bilskrot Göteborg
  25. Pingback: chimney
  26. Pingback: juegosfriv.one/
  27. Pingback: testo 500
  28. Pingback: mark curry
  29. Pingback: Bitimart
  30. Pingback: testomax200

Comments are closed.