protected virtual methods in f# -
- f# not support definition of
protected
methods. here explained why - f# replaces
virtual
methodsabstract
methods defined in abstract classes (see here).
i wondering if there way prevent access abstract
methods outside derived classes @ all.
like patryk Ćwiek, don't think it's possible, here's 1 alternative:
from design patterns know should favour composition on inheritance. in experience, can inheritance, can composition. example, can replace template method strategy.
a template method typical use of abstract method, if replace strategy, can (sort of) hide clients:
type foo(strategy : ibar) = member this.createstuff() = // 1. concrete here // 2. use strategy here // 3. else concrete here // 4. return result
no outside client of foo
can invoke strategy
, accomplishes same goal making member protected.
you may argue original creator of foo
may keep reference strategy
, , still able invoke it. that's true, protected members aren't hidden either, because can derive class in question, enables invoke protected member.
another point if separate creator of foo
client of foo
, strategy
unavailable client.
Comments
Post a Comment