In Scala, I would write an abstract class with the abstract path attribute:
abstract class Base { val path: String } class Sub extends Base { override val path = "/demo/" }
Java does not know abstract attributes, and I wonder what would be the best way to get around this limitation.
My ideas:
a) constructor parameter
abstract class Base { protected String path; protected Base(String path) { this.path = path; } } class Sub extends Base { public Sub() { super("/demo/"); } }
b) abstract method
abstract class Base {
Which do you like best? Other ideas?
I try to use the constructor as the path value should not be computed at runtime.
java oop scala abstract-class attributes
deamon
source share