Initialize() vs Constructor() method, proper usage on object creation

I think there are multiple aspects that should be taken into consideration:

  • A constructor should initialize an object in a way that it’s in a usable state.

  • A constructor should only initialize an object, not perform heavy work.

  • A constructor should not directly or indirectly call virtual members or external code.

So in most cases an Initialize method shouldn’t be required.

In cases where initialization involves more than putting the object into a usable state (e.g., when heavy work needs to be performed or virtual members or external need to be called), then an Initialize method is a good idea.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)