.Net and Design Patterns

Evolution has a spiral nature… it is true for any science, process, or development.

Not long time ago Waterfall Model of development prevailed. Very formalized, well described and structured, very structured… and it was “too much” which killed it… like a grandpa, it collected a lot of knowledge and experience, but he was to old and slow to keep up with the grandson… So was WF model – developers wanted something better and simpler, with built-in flexibility and after few iterations we’ve got “Agile model” and “XP programming” emerged. “Spiral” development cycles… “loose” modeling… like with JPEG, developers got “loose compression” of software process definition.

Not that we are loosing quality of the development, but we define the development process with desired level of formality/quality.

Remember in “Pirates of Caribbean” – pirates have “the pirate code”. Not being the law, it was a code of conduct which was helping keep the structure and discipline.

Same for “free spirit” development models, there is the need for some “guidelines” or “rules” everybody can understand and follow if want to achieve structure and efficiency. For the process there is an Agile methodology, and for the code/architecture there are Design Patterns.

First introduced over 30 years ago, term “Patterns” surfaced in software industry several time: originally in 1977, then in 1987 and then finally in 1994.
Since that time and Object Oriented Design becoming main stream in Software Industry it transformed into a common terminology.
It still come in “waves” to one company or another, coming ashore and and then retracting back to the sea of the theories. But with Object Oriented Programming being a mainstream in evolution of software development, Patterns or Design Patterns knowledge become a common base.

Today you hear about it everywhere – “What design pattern did you use?”, “application blocks“, etc.

To think about it, there is nothing new here. As an OO developer you may used it just a minute ago.

So let’s name a few basic one (I am going to use pattern classification presented here or you can refer to The Source – “Design  Patterns” by Gamma/Helm/Johnson/Vlissides (Amazon)):

  • Abstract Factory – allows manage/create instances of several types of classes – generic access.
    A-ha! In .Net the perfect example would be generics and reflection – there you are working with objects without precise knowledge of their type or parameters.
  • Singleton – have you ever created global instance of the class? This is a one example for you.
  • Adapter – we heard it somewhere recently… Aaaa… OleDBDataAdapter… From MSDN: “The OleDbDataAdapter serves as a bridge between a DataSet and data source for retrieving and saving data”
  • Bridge – have you moved from Single/mono-design applications to C/S or created front-end ASP.Net page for your Application Server back-end? Then you have separated interface from implementation of the logic, or used a Bridge pattern.
  • Proxy – Accessing your web-service from your code? Then you have most likely using some sort of Proxy class.

And then you look at WPF and see more complex like WPF patterns.

You start with just 3 groups of two dozen design patterns and you end up with many more. Some are more common then others. As it did happen with XP and Agile, and other “new” things, it all falls back to the knowledge of terminology and “buzz” words.

What does knowledge of DP give you? In reality it can come to – “not much” and “a lot”. Statements contradicting each other? Well.

Let’s look at the definition:

Design Pattern is a general reusable solution to a commonly occurring problem in software design. It helps a designer/developer/architect get a design “right” faster.

As you can see from definition, you may know them from acquired knowledge, common experience. After several years of development, you have your own patterns/templates, common practices in solving common problems. As a result, learning about “Design Patterns” may not  give you much of the new knowledge, but may help establish common grounds for discussion with the friend in next cubicle.

Ok, lets come back to original idea of .Net and design patterns. Why is it so important these days? Is it important to bring two together?

.Net framework, C# in particular, become a fine example of Object Oriented Design implementation. With language structures and Object Models present in .Net framework, it is important to understand principles of Object Oriented Design and Object Oriented Programming.

Object-oriented design (OOD) is a programming paradigm that began in the late 60’s as software programs became more and more complex. The idea behind the approach was to build software systems by modeling them based on the real-world objects that they were trying to represent.

Object-oriented programming (OOP) is a programming paradigm that uses “objects” and their interactions to design applications and computer programs. Programming techniques may include features such as encapsulation, modularity, polymorphism, and inheritance.

Combine them all and you will get .Net 3.x – WPF/WCF/LINQ frameworks. With WPF patterns and all, in order to get most out of the framework theory part of OOD/OOP become even more important because it is built-in/core part of the new concepts behind class/event/organization model of the latest edition of the framework.

You just thought that you know it all about C#? Well… it is time to start the next learning cycle. 🙂

PS. There are few things to read and watch:

  • “Tales from the Smart Client” by John Gossman, Microsoft Architect for WPF and Silverlight. … You will find many posts about design and patterns in WPF.
  • Another good source is dnrTV!. It now has more then a hundred shows discussing different aspects of .Net framework application: training videos, interviews and more…
This entry was posted in Fun stuff with C#, Technology and tagged , , , , . Bookmark the permalink.

Leave a Reply