daniloquio daniloquio - 27 days ago 21
C# Question

Standard term for instantiation practice

Is there a standard term for the practice of instantiate a class without using an explicit constructor but instead initializing some of its properties?

new SomeClass { PropertyA = true, PropertyB = "ugly code is ugly" };


I'm guessing there could be a standard not judgemental term and then there could be a negative term.

** --- ** --- EDITED POST CLARIFYING COMMENTS AND ANSWERS --- *** ---

Object Initialization it is.

After reading the comments I understand object initialization itself is not a bad practice; the problem is the lack of well defined constructors in favor of object initialization spread across a solution, which makes the solution much harder to maintain and to understand.

An example of bad use of object initialization:


  • Class
    Student
    has 10 properties including
    Code
    and
    Program
    .

  • The code is instantiating this class from 10+ different points.

  • Every time,
    Code
    and
    Program
    are being defined through object initialization.



In this case, class
Student
should have a constructor enforcing
Code
and
Program
to be passed on instantiation.

Answer

It is called Object Initialization

https://msdn.microsoft.com/en-us/library/bb384062.aspx