Skip to content

Commit 5e0ba94

Browse files
committed
about needless (unexplained) complexity using an apply method on a trait's object to create concrete subtypes of the trait. phew!
1 parent 95d7232 commit 5e0ba94

5 files changed

Lines changed: 8 additions & 14 deletions

File tree

src/main/scala/s4j/scala/chapter19/MapExample.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package s4j.scala.chapter19
1818

1919
import java.util.Calendar
2020

21-
object MapExample {
21+
object MapExample extends App {
2222

2323
def age(birthYear: Int) = {
2424
val currentYear = Calendar.getInstance.get(Calendar.YEAR)
@@ -27,7 +27,9 @@ object MapExample {
2727

2828
val birthdays = List(1990, 1977, 1984, 1961, 1973)
2929

30-
birthdays.map(age) // = List(25, 38, 31, 54, 42)
30+
val result = birthdays.map(age)
31+
println(result)
32+
// results in List(27, 40, 33, 56, 44) when run in 2017
3133

3234
// written in-line
3335
birthdays.map(year => Calendar.getInstance.get(Calendar.YEAR) - year)

src/main/scala/s4j/scala/chapter20/Customers.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ trait Customers extends Iterable[Customer] {
2020
def add(Customer: Customer)
2121
def find(name: String): Option[Customer]
2222
def findOrNull(name: String): Customer
23-
}
24-
25-
object Customers {
26-
def apply() = new CustomerSet()
27-
}
23+
}

src/main/scala/s4j/scala/chapter20/Example.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package s4j.scala.chapter20
1919
import s4j.scala.chapter20.CustomerDatabase.database
2020

2121
object CustomerDatabase {
22-
val database = Customers()
22+
val database = new CustomerSet()
2323

2424
val customerA = Customer("Albert", Some(Address("1a Bridge St", None)))
2525
val customerB = Customer("Beatriz", None)

src/main/scala/s4j/scala/chapter21/Customers.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ trait Customers extends Iterable[Customer] {
2020
def add(Customer: Customer)
2121
def find(name: String): Option[Customer]
2222
def findOrNull(name: String): Customer
23-
}
24-
25-
object Customers {
26-
def apply() = new CustomerSet()
27-
}
23+
}

src/main/scala/s4j/scala/chapter21/Example.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package s4j.scala.chapter21
1919
import s4j.scala.chapter21.CustomerDatabase.database
2020

2121
object CustomerDatabase {
22-
val database = Customers()
22+
val database = new CustomerSet()
2323

2424
val customerA = Customer("Albert", Some(Address("1a Bridge St", None)))
2525
val customerB = Customer("Beatriz", None)

0 commit comments

Comments
 (0)