.net - Extension method design guidelines: should a like method name be the same for the sub and super class? -
i finished reading section on extension members in framework design guidelines 2nd ed., krzysztof cwalina , brad abrams, , didn't find example this. question concerns super , sub class in f# library, expect answer relevant .net languages.
f# has 2 types, super type expr , sub type expr<'a> latter wrapper typed version of former. these types used quotation expressions.
if wanted define extension methods on these types evaluating them, better design:
- do f# powerpack , defined methods different names
evaluntyped() : expr -> objonexpr,eval() : expr<'a> -> 'aonexpr<'a>. - do closer if owned types , use same name (where method on super type can thought of virtual, , method on sub type can thought of overriding super virtual method). i.e.
eval() : expr -> objonexpr,eval() : expr<'a> -> 'aonexpr<'a>.
the second option seems more correct me, i'd follow whatever design guidelines there may be: there authoritative precedence (supposing got "wrong" in powerpack)?
there may not definitive answer this. however, unless believe f# powerpack did design "wrong", i'd follow style 2 reasons:
- to keep style consistent other developers work in f# , official extensions.
- to more explicitly show difference in return types of 2 methods since matter.
your analogy in reply tomas one, i'd assume other developers using code may not pay attention design have. best keep consistent official style , explicit in intentions.
Comments
Post a Comment