In C # you are allowed getters and setters with access levels (see access modifiers ) that are different from the general property. This is the most common pattern.
public class FooObject { public String Foo { get; private set; } }
This allows objects creating an instance of FooObject to retrieve the value of Foo, but not to set its value. A private modifier on the installer means that only this method has only FooObject (not including the use of reflection).
There are two advantages to this:
With the addition of automatic properties (no variables require assigning get and set values), this allows you to use the private parameter of the property variable (created for you at compile time) so that this is done without the need to explicitly create the variable. Without this, you could not use the automatic property, if only you always wanted the get and set function to be public, all private, etc.
It allows the level of abstraction so that all methods, whether public, private or otherwise, go through a property and not directly access a private variable. See question for details.
In your instance, other objects can set the value of the factory session, but only its inheriting classes can retrieve it. In most cases, if an object can set a value, it can also get it, but there are times when it would be useful not to allow it. This is allowed because the specified event does not allow more access than what was defined for the common property.
The best example I can think of would be if the given object were modified on a given event. For example, if this specified event was set for a connection object, and a connection string was added in the setup event and a connection to the database was opened (in my example, I will probably reorganize the code so that it does not act in this way, but it may occur something like that).
source share