February 25, 2021
Hot Topics:

Why Use Design Patterns for Building .NET Applications?

  • By James Maioriello
  • Send Email »
  • More Articles »

Another useful pattern is the Proxy Pattern. The intent of the Proxy Pattern is to provide a surrogate object for another object in order to control access to it. For example, the surrogate object can be designed to cache frequently accessed, but static, data locally to minimize access to a remote server object. Several of the classes in the System.Runtime. Remoting namespace provide support for creating proxy objects and serializing their representation.

Behavioral Patterns

In addition to structural patterns, behavioral patterns have also been described to solve design problems relating to application behavior. The .NET platform makes extensive use of design patterns to promote loose coupling between classes. For example, Delegates use the Observer Pattern to provide a callback mechanism whereby an object that raises an event can invoke method calls on event handling objects without the client's knowledge. In this model, the event sender declares an object called a "Delegate." Any classes wishing to be notified of this event will simply provide a method with the same signature as the Delegate. This method would then respond to the event. This approach allows you to easily add additional event receivers without the need to modify the event sender code. All you need to do is create a method with the same signature as the Delegate and respond to the event. The delegate provides a level of indirection by keeping the event sender from knowing which object will receive the event.

This mechanism can be further enhanced using the Chain of Responsibility Pattern. This design pattern describes an approach to avoid coupling between the sender and recipient of a message while allowing more than one object to have a chance to respond to the message. In .NET, this pattern can be implemented using Multicast Delegates. A multicast delegate differs from a regular delegate in that it references to more than one method. When the multicast delegate is invoked, the methods are executed synchronously in the order in which they appear. Thus, you can pass an event to a chain of objects and give any one of them a chance to respond. This pattern is very useful for maintaining event handlers for menu items and other interface controls.

Another useful pattern is the Command Pattern. This pattern describes a way to encapsulate a request as an object. This allows you to parameterize the request and pass it on as an object. .NET incorporates the intent of the Command Pattern by providing the System.EventsArgs. Your custom types would derive from this class so you can define custom data associated with events.

In conclusion, many developers will be approaching .NET from a background in Visual Basic, which lacks many of the features of an Object Oriented Language. Design Patterns give these developers a way to build .NET applications while incorporating good software engineering principles.

James Maioriello, Ph.D., is a Senior Design Engineer for Formation Systems Inc., a corporation located in Massachusetts dedicated to the development of software systems for product development in the processing industries. His position allows him to use his expertise and skills to design solutions for chemists and other scientists so they can focus their talents on innovation. Dr. Maioriello obtained degrees in Chemistry from Lehigh University and in Software Engineering from Polytechnic University in New York.

Page 2 of 2

This article was originally published on May 15, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date