Complex properties violate the principle of least surprise - the caller expects that when the property can be set once, it can be set again. (of course, spaces and compatibility checks, but they are tied to specific values โโor combinations of values).
Initialize them in the constructor.
Alternatively, if they are for many / difficult to write all the constructors, use the factory / builder class:
ThingieBuilder tb = new ThingieBuilder(); tb.FooThingy = 17.23; // r/w properties tb.BarThingy = 42; tb.UseExtendedThingamagicAdapter = true; Thingie t = tb.Create(); if (t.Bar==42) // r/o property ...
Or separate the settings in the configuration object, which can be replaced or transferred at build time.
peterchen
source share