Monday, February 8, 2010

Question #1 for the readers: Which design pattern is used here?

@YaronNaveh

There's an interesting design patterns riddle for you readers in the end of this post.

Jesse wrote an interesting post about xml and the .Net framework. He reminds us that xml is actually an abstraction and that Angle brackets are just one (inefficient) way of representing it.

For this reason this code:


...
xmlWriter.WriteStartElement("rawBytes");
xmlWriter.WriteBase64(arr);
xmlWriter.WriteEndElement();
...
xmlWriter.WriteStartElement("blog");
xmlWriter.WriteString("yaron's blog");
xmlWriter.WriteEndElement();
...


can actually generate both "regular" xml and optimized binary one, depending on the implementation of XmlWriter handed to it.

This is actually a great example of a design pattern implemented in the .Net framework BCL.

Can you guess which design pattern is it? Here's the DP list. Give your best shot at the comments bellow!

@YaronNaveh

What's next? get this blog rss updates or register for mail updates!

4 comments:

Pablo Alarcón said...

That's the Builder Pattern

Moshe said...

Microsoft implemented here only a "preparation" for the Builder pattern - they assume that people will use the XmlWriter methods in order to construct XML documents. In other words Yaron's code is the missing "Director" part. But if one uses the XmlWriter method for other purposes (for example in order to create load conditions by consuming memory with arbitrary calls to the XmlWriter methods) - no builder takes place.

Dmitry Ornatsky said...

Builder, beyond doubt

Yaron Naveh (MVP) said...

You're all right - builder it is