<= Home

XInclude and the decorater pattern in .NET

Posted about over 2 years ago

Bill Ryan asked if there where any implementations of the decorator design pattern in the .NET Framework. – So this is my response:

System.IO namespace is a good place to start. The System.IO.Stream is the base class that you can ‘decorate’ with a System.IO.MemoryStream, System.Security.Cryptography.CryptoStream, and many more. Also true to the decorator pattern you can combine these any way you choose.

Another example is the XmlReader (think XmlValidatingReader decorates XmlReader). I have decorated the XmlReader with my own implementation of the W3C’s XInclude specification. Warning - unfortunately it is not a full implementation of the specification, but it demonstrates the decorator pattern well. Use this by creating an instance of XmlTextReader and pass it into the XmlXIncludeReader constructor and it will include any external xml files.

See sample here - I had to remove code here - taking up too much real estate.