// like a Java interface trait Customer { def getPlan: String } // like a Java class with a static method object BillingPlan { def basic: String = "basic" }
Using Introduce Null Object we would write
def f(c: Customer) = val plan = if(c == null) BillingPlan.basic else c.getPlan ...
Using Scala's Option
we would alter the type to Option[Customer]
and use
higher-order functions
def g(c: Option[Customer]) = val plan = c map (_.getPlan) getOrElse BillingPlan.basic ...
Does it stop there?