score:0

a first step to an answer to might look like this

class animalia {
  type fundamentalcelltype = eucharyotic // all sub species inherit from this.
  val hasdifferentiatedtissues: boolean

  type phylumt <: animalia
  val phylum : phylumt
  type klasst <: phylum.type //not sure if this would work.
  val klass: klasst
  type genust <: klass.type  //intermediate classification left out for simplicity
  val genus: genust
}

score:1

you are confusing an inheritance hierarchy with the hierarchical biological classification of things! for example; why would chimpanzee be an animalia? why would a species be a phylum? these are distinct concepts.

what you are really looking for is aggregation (apologies for my lack of biological correctness)

trait animalia { def phyla: list[phylum] }

then we might have:

trait family { def phylum: phylum }
trait genus { def family: family }
trait species { def genus: genus }

and an instance of this:

object primates extends family { val phylum = mammals }
object apes extends genus { val family = primates }
object homosapiens extends species { val genus = apes }

score:2

oo inheritance modeling is simpler than it seems. the extends keywords is a synonym for "is-a" relationship. so a "chimp is a primate and all primates are mammals" is meaningful so you can model this relationship as:

trait primate extends mammal
class chimp extends primate

but the relationship "a primate is an order" does not holds. so you cannot model it by inheritance. however, the "primate order is an order" is meaningful and you can model this relationship as:

object primates extends order
object mammals extends klass

you can then say that "chimp belongs to the primateorder", but that's a different relationship, that you can model as:

trait animal {
  def order: order
  def klass: klass
}
trait mammal extends animal {
  val klass = mammals
}
trait primate extends mammal {
  val order = primates
}
class chimp extends primate

chimp.order //=> primates
chimp.klass //=> mammals

Related Query

More Query from same tag