Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OO in Scala - The unloved side of the cake?

OO in Scala - The unloved side of the cake?

Component composition in Scala using a variant of the cake pattern

Tobias Neef

April 17, 2013
Tweet

More Decks by Tobias Neef

Other Decks in Programming

Transcript

  1. How

  2. I

  3. Who

  4. IoC

  5. trait Component { def instance : ManagedClass trait ManagedClass {

    def method():Int } } Component Context Logic Context
  6. trait Component { / / New Instances / / Unique

    Instances / / Dependencies / / Component Inheritance }
  7. trait ManagedClass { / / normal class / / access

    to component / / application logic }
  8. trait AuthComponent { def authComponent: Auth trait Auth { def

    load(name: String, pass: String): Option[User] protected def internalUser() = .. } }
  9. trait BookingServiceComponent { ! self : AuthComponent => def bookingService

    = ! new BookingService() class BookingService { def book(user: String, pass: String, !! itemId:Id) = ! ! ! authComponent.load(user,pass) ... } }
  10. trait LocalAuthComponent extends AuthComponent { def authComponent = new LocalAuth()

    class LocalAuth extends Auth { def load(name: String, pass: String) = ... } }
  11. trait LDAPAuthComponent extends AuthComponent { def authComponent = new LDAPAuth()

    class LDAPAuth extends Auth { def load(name: String, pass: String) = ... } }
  12. Is made of the core Scala language It is checked

    at compile time It requires no IoC It uses the most specific type available It can express cyclic dependencies It can’t change its configuration at runtime The Cake
  13. trait GlobalActorSystem { private[core] def actorSystem: ActorSystem private[core] implicit val

    defaultTimeout = Timeout(4,TimeUnit.SECONDS) } Default Implicits Technical Context