c# - create an instance of a manager class -


let's have class customermanager lot of methods interact dal.customermanager. there lot's of mehods not interact dal.customermanager class.

should instantiate _dalcustomermanager class code below?

public class customermanager {      private dal.customermanager _dalcustomermanager = new dal.customermanager();       public void deletecustomer(int customerid) {         // .. logic here ...         _dalcustomermanager.deletecustomer(customerid);     } } 

or better solution because don't instance of _dalcustomermanger , when access dalcustomermanager property creates new instance of when it's null ?

public class customermanager {      private dal.customermanager _dalcustomermanager;     private dal.customermanager dalcustomermanager {           {              return _dalcustomermanager ?? (_dalcustomermanager = new dal.customermanager());                          }     }       public void deletecustomer(int customerid) {         // .. logic here ...         dalcustomermanager.deletecustomer(customerid);     } } 

this matter of taste. unless dal.customermanager() has extensive constructor (like allocating lot of classes, doing time consuming work) doesn't matter.

this link might find useful (about micro optimization in general) : http://blog.codinghorror.com/the-sad-tragedy-of-micro-optimization-theater/

also i'd point out lazy loading of dal.customermanager in code not thread safe:

private dal.customermanager dalcustomermanager {    {      // if 2 threads calling you'll allocate 2 instances.     return _dalcustomermanager ?? (_dalcustomermanager = new dal.customermanager());                   } } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -