Should constructor variables go directly to private fields or properties?

Now it is .NET, but I am sure that the principal should be applied to all OOP languages ​​in order to simplify the use of .NET as an example:

R # is usually the creator of the constructor and passing the incoming variable to a private field, which for me, as a rule, passes it to Property.

Any opinion on how different and what is best for?

+3
source share
5 answers

, /. - , , , , . Microsoft , , , ( , , , .NET - ).

+5

.

+3

Property, , . , , , . , , Property .

+3

Set Setter. , .

+2

. , - . .

The conversion logic applied to constructor arguments or input property values ​​before setting the internal state of an object can be very different. Anyway, if so, I used an explicit conversion method called from the property definition tool and from the constructor, instead of directly linking the constructor to the property setting device.

If there is no logic at all, I don’t understand why you want to use the setter property inside the constructor.

+1
source

Source: https://habr.com/ru/post/1697503/


All Articles