Monday, March 12, 2012

why to use constructors

what is the advantage to use a constructor and passing arguments to it rather than using the functions and sub arguments??You need less operations targeted for the object you set arguments for.

For example if you create object that takes five arguments. You could instantiate the object and set all five arguments at once or you could create the object and call 5 different methods (or you would use properties actually), that makes 6 operations when with instantiation it is only one.

Certainly the picture isn't that black and white always for example only certain values could be set when object is constructed and only certain via propeeties (requirements by the business logic).

0 comments:

Post a Comment