Wednesday, September 27, 2006

Garbage collection DO exists in C#

The .NET Framework is a very advanced framework as it has two different types of garbage collection. Like Java it is able to remove objects that is not in use anymore without being told and do it automatically. But .NET also has another GC that Java doesn't have. It is not the normal GC that you would assume, but it is highly integrated into the WinForms framework.

This new garbage collection is a property named Tag in the Control class. This is a place where you can put any garbage into that you could use later. The Controll class will store it for you forever, which is nice when you want to have garbage lying around. So with this enhanced garbage collection, you can store all your garbage and it looks like it is good OO.

The idea behind the Tag property is to store objects for combo box and list items, which is later used when a list item is selected and the object "representing" is needed. It seems that MS has come up with their own solution to the well known Model-View-Control pattern for GUI development. What they came up with is that every GUI control needs to have a model/data, and therefore it is wise to add such functionality to the Control class. The problem is that changing the model (Tag property) does not have any effect at all, the list or combo boxes doesn't change when the Tag property is updated. It is just a place to store objects; it isn't really MVC, is it?

The thing with Java, which tries to enforce the MVC (or at least MV) it is that the GUI devloper has to seperate the model from the view (and control). With .NETs approach you most of the time end up with a Form that has several Control objects and data in one class. I thought OO was to go away from the One-File(-To-Rule-Them-All) idea and seperate code. Now that MS still lets the developers use the Tag property, they are not helping us to seperate logic from representation. And it sucks, because we developers are lazy. We really need someone standing behind our back so we code "correctly".

Once again, I'm sitting wishing that my current project was developed in Java and not in .NET 2.0, because I do not want to work store everything in one class.