C# – Creating Class Files, Cohesive Classes and Code Navigations
Prefer more classes w/ narrowly defined responsibilities.
Prefer to put each class in its own file.
Prefer high cohesion – similarity singleness of purpose of the class members.
To achieve high cohesion, a rule of thumb: try to make your classes fit on one “screen” of your IDE(no scrolling required).
Understanding Object References and Object Lifetime
An object reference variable holds a reference to an instantiated object in the computers memory.
The new keyword creates an instance of the class and returns the address of object in memory to the reference variable.
myObject = new myClass();
More than one object reference variable can hold an address to the object in memory.
myClass myOtherObjectReference = myObject;
Each time new reference is added, the reference count increases by one. Each time an object reference variable goes out of scope or is set to null, the reference count decreases by one.
If the reference count is zero, .NET Framework Runtime’s Garbage Collector removes the object from memory at an inderminate point in time in the future. You can take control of the finalization process and even handle events just before the object is removed. See: “deterministic” finalization.