protected virtual methods in f# -


  • f# not support definition of protected methods. here explained why
  • f# replaces virtualmethods abstractmethods 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

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -