c# - Heavy Constructors or use a method -


both of these methods kind of working me, i'm not sure recommendation "good practice" point of view.

i have class performs various control functions within library, needs initialise sorts of objects , properties.

is okay put logic in constructor class, or should put in "initialise" method.

public myclass() {     msubobjecta = new msubobjecta();     msubobjecta.dostuff();     msubobjecta.domorestuff();      msubobjectb = new msubobjectb();     msubobjectc = new msubobjectc();      if (something)     {         dostuff();     }     else     {         magichappens();     } } 

it depends on how many constructors think have. don't repeat code. if of these steps happen in 1 constructor, it's not problem. if you're looking more fancy, intelligently arrange code.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -