Untitled

 avatar
unknown
scala
4 years ago
430 B
13
Indexable
object Hello extends App {
  val element: Element = new UniformElement('#', 7, 7)
}

abstract class Element {
  def contents: Array[String]
  val height = contents.length
  val width =
    if (height == 0) 0 else contents(0).length
}


class UniformElement(
  ch: Char,
  override val width: Int,
  override val height: Int
) extends Element {
  private val line = ch.toString * width
  def contents = Array.fill(height)(line)
}

Editor is loading...