Applying the Decorator Pattern to a DataGridView

Article Index:

«»


In this article, I present a simple example of how you can apply the Decorator Pattern to a DataGridView to extend its behavior without using inheritance. This article is not meant to be a tutorial on the Decorator Pattern. Rather, it is just a brief explanation of how I solved a particular design problem using a variation of the Decorator Pattern. With a bit of thought, the reader should be able to apply my design pattern to decorate other types of visual controls and components from the .NET Framework such as Button, CheckBox, ComboBox, Label, ListBox, ListView, Panel, TextEdit and TreeView.

Hopefully, you already have some idea of what the Decorator Pattern is and what it is used for. In case you don’t, the classic definition from the Gang of Four’s seminal book Design Patterns: Elements of Reusable Object-Oriented Software is:

Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

A classic example of the Decorator Pattern is where you start with a basic StreamReader to read characters from a byte stream and then you decorate it once to add decryption and decorate it a second time to add decompression. In this case, using decorators saves you the hassle of creating subclasses for every combination of behavior you might want in a StreamReader. Without the Decorator pattern, you might have to create DecompressingStreamReader, DecryptingStreamReader, DecompressingAndDecryptingStreamReader, LoggingAndDecompressingAndDecryptingStreamReader, etc.




Article Index:

«»

Pages: 1 2 3 4

1 comment to Applying the Decorator Pattern to a DataGridView

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>