Multiple constructors with inheritance c# -


i have base class b multiple constructors. have derived class d has additional fields set in constructor(s), implemented shown below.

b(args1) {...} b(args2) {...} ... b(argsn) {...}  d(args1, additional) : b(args1) {...} d(args2, additional) : b(args2) {...} ... d(argsn, additional) : b(argsn) {...} 

problem is, every time new b constructor added new args have make new d constructor. way around this?

you have define constructor in derived class if want in base class , expect them identical. could, however, use default values suggested. or, have dictionary-based constructor, derived classes grab values from.

could use alternative design pattern factory method, factory, or simplify constructor approach?

if want constructors , want add complicated solution, use following. not recommending it, use code sharing/generation technique combination of partial classes (define 1 partial class constructors, , other has of properties/members/etc.) , in partial class has constructors, t4 template overwrites when base template changes. again, adds lot of overhead... don't know how many classes talking about, , how exact want them.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -