Versioning Capabilities of C#


Many developers think that object-oriented approach to software development is the only way to develop software, but is it really? When C++ was introduced, it solved many of the limitations of C's structured programming approach. C++ however introduced a new set of problems. Try and picture the following scenario.

Assume for the moment that we have a base class, called Shape. After spending our precious time completing and writing the class, we now released it to the world for other programmers to use. Another programmer in a different section, working on a different project decided that the Shape class suited him well and derived it to create another class, called Square.

Here's where object-oriented language has a distinct advantage. Any changes to Shape will not have a direct effect to the Square class. The class author of the derived class Square decided that he needed a new method and called it Draw(). Again, because it is a derived class, it will not have an effect to the base class, Shape.

class Shape {
}

class Square : Shape {
public void Draw() {
}
}


However, we've decided to modify the base class to have the method Draw(). We now have a situation where the base class has a method called Draw() and the derived class has a different implementation of the same function name. A C++ compiler will complain about this type of situation. To make things worse, the base class was a purchased, third party commercial product. This means that getting the publishers to change their naming convention is unlikely to happen.

You can change the function name to something different, but you would also have to search through all your source code that uses the method Square.Draw() to the new name. It sort of defeats the purpose of having component software. In C#, there is the concept of versioning, which according to the C# Language Specification, is the process of evolving a component over time in a compatible manner.

For experienced C++ programmers, you might be screaming "virtual" modifier. Adding a virtual modifier does not help and make the implementation of the derived class unclear. The intent of the author of the derived class is not clear as to whether Draw() is a completely separate implementation or is it a modified version of the base class?

In any design of newer programming language, the objective is always to eliminate the discrepancies between intent and action. Citing the above situation, the intent of the programmer of the derived class is not clear and this has always been the situation with C++. In C#, two new keywords are introduced to avoid this very confusion.

The copyright of the article Versioning Capabilities of C# in C# Programming is owned by Jose Aniceto. Permission to republish Versioning Capabilities of C# in print or online must be granted by the author in writing.

Go To Page: 1 2

Articles in this Topic    Discussions in this Topic