what exactly is the difference between `B` and `D`...
# announcements
l
what exactly is the difference between
B
and
D
here (other than the name) ? I've noticed that in
B
i can use
super.x
which i can't do in
D
, but there doesn't seem to be any use in that since bot
x
and
super.x
point to the same variable note: i know that
A
technically doesn't need to be
abstract
in this example. just assume that there's other abstract properties that require
A
to be
abstract
also, which should i use when, and why ?
d
The difference is where the field is defined. He who defines the field has more power to do interesting things with said field.
I tend to use D just the give subclasses more flexibility.
Or maybe I don't like giving abstract classes constructors, hmm dunno.
l
can you name one such "interesting thing" ?
d
You can define the field as
var
in the subclass for example.
You can use delegates, or intercept the getter in general I guess.
You can return a more specific type in the subclass.