c# - "Base abstract generic class is a bad choice in most situations." Why? (Or Why not) -


i have seen on comment blog post:

base abstract generic class bad choice in situations

is true, if not why?

what insight(s) leads statement?

"most situations" outrightly vague. generic abstract class (or interface) bad idea if common ancestor between descendants of such class system.object (as noted other commenters of question).

otherwise (as in, if have meaningful common ancestor), it's idea if want "rename" or "specialize" members. consider example:

// meaningful common ancestor working classes. interface iworker {    object dowork(); }  // generic abstract base class working classes implementations. abstract workerimpl<tresult> : iworker {    public abstract tresult dowork();     object iworker.dowork()    {       return dowork(); // calls tresult dowork();    } }  // concrete working class, specialized deal decimals. class computationworker : workerimpl<decimal> {     override decimal dowork()     {        decimal res;         // lengthy stuff...         return res;     } } 

in example, dowork() redefined in abstract class, becoming concrete , specialized in computationworker.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -