title: Case classes inheriting from abstract class
body: <p>I'm currently learning Scala and I have some problems designing my case classes. I need two case classes that have the same properties. So I thought I would be a good idea to inherit from an abstract base class that defines these properties. However this code does not compile</p>
  
  <pre><code>abstract class Resource(val uri : String)
  
  case class File(uri : String) extends Resource(uri)
  case class Folder(uri : String) extends Resource(uri)
  </code></pre>
  
  <p>because <code>uri</code> in the case class constructors would overwrite the <code>uri</code> property of the base class.</p>
  
  <p>What would be the correct way to design this?</p>
  
  <p>I want to be able to do something like this</p>
  
  <pre><code>val arr = Array[Resource](File("test"), Folder("test2"))
  
  arr.foreach { r : Resource =&gt; r match {
    case f : File =&gt; println("It's a file")
    case f : Folder =&gt; println("It's a folder")
  } }
  </code></pre>
  
  <p>The "equivalent" Java code should be something like</p>
  
  <pre><code>abstract class Resource {
     private String uri;
  
     public Resource(String uri) {
         this.uri = uri
     }
  
     public String getUri() {
         return uri;
     }
  }
  
  // same for Folder
  class File extends Resource {
      public File(String uri) {
          super(uri);
      }
  }
  </code></pre>