Linked Questions

2028 votes
37 answers
518k views

Why prefer composition instead of inheritance? What trade-offs are there for each approach? And the converse question: when should I choose inheritance instead of composition?
readonly's user avatar
  • 358k
348 votes
7 answers
165k views

I was making my way through the Scala playframework tutorial and I came across this snippet of code which had me puzzled: def newTask = Action { implicit request => taskForm.bindFromRequest.fold( ...
Clive's user avatar
  • 4,021
61 votes
7 answers
39k views

Favor composition over inheritance is very popular phrase. I read several articles and at the end each article says use inheritance when there is pure IS-A relationship between classes. An example ...
a Learner's user avatar
  • 5,052
47 votes
2 answers
158k views

I am new to JAVA and just started learning "IS-A" and "HAS-A" relation but I didn't really get it. What is the difference between "IS-A" and "HAS-A"? When ...
Milan's user avatar
  • 821
96 votes
3 answers
8k views

In Scala, we can use at least two methods to retrofit existing or new types. Suppose we want to express that something can be quantified using an Int. We can define the following trait. Implicit ...
ziggystar's user avatar
  • 28.7k
13 votes
2 answers
34k views

Possible Duplicate: Prefer composition over inheritance? What is the difference between inheritance and delegation in java? How to use the following example in my project? Please can you guide me ...
Shilendra Sharma's user avatar
2 votes
1 answer
2k views

I've stumbled upon this thread and there @prolativ provided some fancy scala 3 syntax for creating extension methods for objects extension (int: Int.type) def unapply(s: String): Option[Int] = s....
Killjoyer's user avatar
0 votes
1 answer
1k views

I am reading a Spark in Action book, I came across a construct that even after a while working with Scala I still can't understand. Here is the code (complete code) : First we have a case class where ...
Adelin's user avatar
  • 19.2k
0 votes
1 answer
268 views

I have a scenario where I would like to call sum on a sequence of (Double, Double) tuples. Ideally I would like to do something like the following: implicit def toTupleNumeric[T](num: Numeric[T]) = ...
user79074's user avatar
  • 5,412
0 votes
1 answer
218 views

I'm new in Scala Here's what I'm trying to understand This code snippet gives me RDD[Int], not give option to use toDF var input = spark.sparkContext.parallelize(List(1,2,3,4,5,6,7,8,9)) But when I ...
Javastudent's user avatar