Skip to content

Instantly share code, notes, and snippets.

@sonumehrotra
Created December 3, 2020 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sonumehrotra/8b2205e23b5633d367e42d5183f2f335 to your computer and use it in GitHub Desktop.
Save sonumehrotra/8b2205e23b5633d367e42d5183f2f335 to your computer and use it in GitHub Desktop.
object Order extends App {
trait Order {
val quantity: Int
val printQuantity: String = s"This order has a quantity of $quantity"
}
class Buy(q: Int) extends Order {
override val quantity: Int = q
}
class Sell(q: Int) extends Order {
override val quantity: Int = q
}
object Trade {
def buy(q: Int): Buy = new Buy(q)
def sell(q: Int): Sell = new Sell(q)
}
val buy1 = Trade.buy(100)
println(buy1.quantity)
println(buy1.printQuantity)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment