And you thought all you got was OOP
by Todd Bryant, MCT
Visual Studio .NET and the .NET Framework is Microsoft's first fully object oriented development environment and platform. The inclusion of OOP in the framework is arguably the single greatest gain for developers with respect to productivity and code reuse. OOP is definitely the feature that has generated the most hype.
OOP grants or enforces certain behaviors through two mechanisms:
- Inheritance: Inheritance gives you abilities or behaviors based on ancestors. An example would be a "fruit" class. If a "ripen" behavior is built into this class, then I would automatically get this behavior in any classes that inherit from fruit.
- Interfaces: Interfaces allow you to enforce behavior for unrelated items where an inheritance relationship makes no sense. An apple and a potato are unrelated items in that one is a fruit and one is a vegetable. They do have similar behaviors in that both might need peeling before being eaten. In this instance, it would be prudent to create and use an interface.
I bet that you did not know that Microsoft threw in another cool programming paradigm for free. This new programming method is Aspect Oriented Programming or AOP. So what is AOP? I am glad that you asked.
Aspect-Oriented Programming is a programming paradigm conceived by Xerox PARC in the 1990s. It allows a developer to better separate specific tasks that are common to unrelated items. The AOP approach has a number of benefits. First, it improves performance because the operations are more succinct. Second, it allows programmers to spend less time rewriting the same code. Overall, AOP enables better encapsulation of distinct procedures and promotes future interoperation.
Microsoft implemented AOP with the use of their new attribute feature. You apply an attribute to a distinct section of code to give it a certain behavior. A good example is serialization. Many objects need to store their internal state so they can be reconstituted later. Microsoft provided the [Serializable] attribute to mark a section of code whose state you want to be preserved when that object is serialized. The compiler then modifies the intermediate language code so the common language runtime knows to save the state of the marked section.
Intermediate Language Code Before [Serializable]
.class private auto ansi beforefieldini SerialTest
extends [mscorlib]System.Object
{
} // end of class SerialTest
Intermediate Language Code After [Serializable]
.class private auto ansi serializable beforefieldinit SerialTest
extends [mscorlib]System.Object
{
} // end of class SerialTest
The .NET Framework is full of other attributes that allow you to modify your code with certain behavior. You can control everything from exposing Web Methods to controlling COM and .NET threading behavior. All of these attributes modify the underlying IL code, providing you with the functionality you want without having to write the code yourself. The biggest win is that you can create your own attributes. This means that you can apply your own custom behaviors to your code. AOP, coupled with the new OOP features will ensure that you and your team are more productive than ever. These are just a few of the reasons that you and your organization should make the jump to .NET.