Wednesday, November 09, 2005

Programming .NET components - A review

The Microsoft .Net framework has provided an elegant programming model that has been well received and proven to be productive for complex managed code. For the non-technical person, that means code executes within a runtime environment that interprets the code before passing it on to the operating system. This allows for safe access to memory and improved security. It also creates a contract of execution between the code and the environment. One of the best things about the .NET framework is the ability to code in multiple languages that can be interpreted into the Intermediate Language understood by the .NET runtime. These languages now range from Cobol to C#, as well as Visual Basic, Managed C++ and Visual J#.

Microsoft has recently released the .NET framework 2.0 providing a variety of enhancements. These include 64-bit platform support, support for custom data types in SQL Server, better authentication, data protection and most importantly generics. New features in Windows Forms, the UI layer of .NET, such as Toolstrips, Layout Panels and DataGrids will appear soon in a window near you.

One of the benefits of .NET is that is makes component-oriented programming much easier and efficient, building on previous technologies that were forbidding in complexity and limited in scope. Programming .NET Components by Juwal Löwy from the fine O'Reilly publishing house provides an excellent guide through the intricacies of component programming in .NET.


It begins with a look at the differences between component-oriented versus object-oriented programming. The author then addresses the principles of component-oriented programming such as binary compatibility, language independence and location transparency, showing how .NET adheres to these principles. He discusses .NET basics from a detailed perspective, covering assemblies, deployment and metadata, providing a Visual Studio 2005 perspective.

Next, aspects of interface-based programming are considered with VS2005 features like the ability to generate skeletal implementations and refactoring. Interfaces are collections of methods that provide access points to the component from external clients. Components can implement any number of interfaces, providing the ability to extend functionality easily without breaking existing clients. Again, generics provide a means of defining an abstract template for an interface and using it on multiple components with different specifications. For example, consider a generic List interface,
public interface IList
{
void AddHead(T item);
T RemoveHead();
void RemoveAll();
}


A component that supports lists of integers could implement this as
public class NumberList: IList
{
public void AddHead(int item){...}
public int RemoveHead(){...}
public void RemoveAll(){...}
...
}


Another component can re-use the interface for a list of strings
public class StringList: IList
{
public void AddHead(int item){...}
public int RemoveHead(){...}
public void RemoveAll(){...}
...
}


This reduces code bloat while preserving type-safety.

The next chapter looks at the niceties of garbage collection in .NET, which deals with the disposal of managed objects created while a program is run. Pre-managed code, memory leakage was commonplace because of programs that did not clean up after themselves. The garbage collector takes care of that for the programmer, although abstruse features such as non-deterministic finalization mean that one cannot be really sure when the garbage collector will come around, although patterns to mitigate this are covered.

After an overview of versioning, including a look at side-by-side execution of multiple .NET CLR versions, the book moves into a set of chapters dealing with critical elements of component-oriented programming - events, asynchronous calls and multi-threading. Events and asynchronous calls are mechanisms to allow components to notify their clients when a specified condition occurs. These could be Windows-type events like Mouse-clicks or custom events. The introduction of generic delegates opens new vistas for event management. Some of the concepts presented here should be part of the .NET framework for their simplicity and brilliance.

Since all .NET programs are multi-threaded, they allow concurrent execution of multiple code contexts. A multi-threaded application is more responsive to users. In the past, development of such applications has not been a task for the faint-hearted. Tthis thorny problem is mitigated in .NET by a number of convenient features for concurrency management, increasing developer productivity. The book looks at the various elements of synchronization, even providing a convenient helper class.

Subsequent chapters cover serialization, remoting and security, with weighty appendices on generics, web services and a C# Coding Standard based on the best practices in this book, itself the de facto standard for C# coders. This is a book with much meat, enough to serve a feast of ravenous developers, starved from nights of toil at the desktops of the giant software factories. The author was recognized by Microsoft as a Software Legend - one of the world's top .NET experts.

Technorati Tags: , , , , , ,

No comments:

Some Fine Books

Blog Archive

Amazon Contextual Product Ads

About Me

My photo

Time traveler, world traveler, book reader