Archive | Design Patterns RSS for this section

Builder

“Separate the construction of a complex object from its representation so that the same construction process can create different representations.”

Design Patterns: Elements of Reusable Object-Oriented Software

Just like the Abstract Factory pattern, Builder is also a creational pattern, with the same goal: create another (in this case, more complex) objects. To stick with the previous data access example, imagine that you have a class with many properties to set, for example, a DbCommand derivate: SqlCommand. You can build SqlCommand objects with the SqlCommandBuilder class, a derivate of DbCommandBuilder. Now SqlCommandBuilder is very intelligent, it builds a complete command object from just a SqlDataAdapter object (which has everything that a command should need: a connection object and a select command object).
Read More…

Advertisements

Abstract Factory

“Provide an interface for creating families of related or dependent objects without specifying their concrete classes.”

Design Patterns – Elements of Reusable Object-Oriented Software

So let’s begin revising the “traditional” object-oriented design patterns. I’m going to stick closely to the book, so the order of posts will be the same as the order in the book.

Abstract Factory is a creational pattern. It means that its sole purpose of such a class is to create another objects/classes. An Abstract Factory pattern has the following participants:

  • Abstract base factory class/interface
  • Concrete factory subclasses derived from the base class, implements the interface
  • Abstract product: the abstract base class of the products to be created
  • Concrete product: the concrete implementation of the abstract product.
  • Client: uses the abstract factory and the abstract product classes, without further knowledge of their concrete implementations.

Read More…

Blog reopened

Welcome back everybody! As you can guess I was a little overwhelmed in the past days, so I’ve lacked the necessary time to write articles in a continuous manner, but that ends today.

The sad part first: I’ve lost my interest in WCF a while ago, so there won’t be any post about it till something extraordinary happens. The happier: I started to work with ASP.NET MVC, and it was love at the first sight. Producing such clean HTML, and the total control over how’s it rendered (not to say anything about built-in URL routing)! But what was far more appealing is the Model-View-Controller pattern.

I found out that I don’t know enough about design patterns as a whole. That gave me the apropos to order the Design Patterns book written by the Gang of Four. From now on, till there won’t be any more left, I post one or two patterns with C# code examples a day, from tomorrow. Be sure to check back!