webknossos icon indicating copy to clipboard operation
webknossos copied to clipboard

Add subclass responsibility error

Open frcroth opened this issue 2 years ago • 2 comments

Sometimes methods are defined in non abstract classes that should be overrridden in subclasses. This is currently done with

  protected def getShardedChunkPathAndRange(chunkIndex: Array[Int]): Fox[(VaultPath, NumericRange[Long])] = ???

or

  protected def getShardedChunkPathAndRange(chunkIndex: Array[Int]): Fox[(VaultPath, NumericRange[Long])] = ??? // Defined in subclass

I would like something more expressive, such as

  protected def getShardedChunkPathAndRange(chunkIndex: Array[Int]): Fox[(VaultPath, NumericRange[Long])] = SubclassResponsibility

like in Smalltalk

frcroth avatar Feb 05 '24 09:02 frcroth

Good idea! The ??? is certainly not very pretty.

What do you have in mind specifically?Should the behavior also change? Or just how this looks in code?

I’m wondering if we could solve this problem in another way entirely with a clever combination of traits? (So that the kind-of-abstract base class/trait does not have to have this ??? in the first place?)

fm3 avatar Feb 05 '24 16:02 fm3

I was thinking replacing the ??? in code so that it is more expressive. The behavior does not have to change (an exception is thrown when called). Just seeing ??? it is not clear if that means "Case can not happen, trust me bro" or "I don't care" or this.

frcroth avatar Feb 05 '24 16:02 frcroth