Perfect match: Composite and Visitor Pattern


In one of my earliest post, I talked about the importantance of understanding principles of good programming, and the useful-ness of Design Patterns… in this post I intend to share some implementation of some of these patterns. Patterns are something I use from time to time on projects, and something that I’m continuously learning from reading and from others, and still enjoying it very much. Let’s proceed then…

Design Patterns can be categorized into creational, structural and behavioral. I find two patterns that work pretty well together being the Composite Pattern (structural) and the Visitor Pattern (behavior). Composite Pattern is a structural pattern that helps one create tree-like hierarchial structures whereas the Visitor Pattern is a behavioral pattern that allows a visitor object to “visit” each element in a structural hierarchy to perform some operation/behavior on that element. Read the rest of this entry »

Advertisements

Using Factory Method Pattern with System.Activator


Over the time I spent developing, I have used Factory Method Pattern numerous times to create my objects. It provides a layer of abstraction by using an interface (or abstract base class) to hide away your concrete implementations. At runtime, we don’t care about the concrete objects that is being returned because we should always strive to program to an interface, not an implementation.
Read the rest of this entry »

Article: Microsoft Patterns and Practices


I came across a good article on MSDN that talks about the separation of concerns using Enterprise Library (now at 4.1), using the Object Builder framework and Unity Application Block for Dependency Injection/Inversion of Control, with examples of incorporating it into Model View Presenter (MVP) pattern.

With quite a number of open source frameworks (like Castle Windsor) out there that do these already, it’s refreshing to see that MS is churning out their own pattern frameworks for .NET Development.

Read article here!

Decorator Pattern with WCF and Castle Windsor


How do you extend a WCF Service that you cannot modify? Or even if you can modify it, should you? Consider the Open Closed Principle. Assuming that you can’t modify the existing service, but want to leverage existing service somehow from your new service, what should we do? That’s where the Decorator Pattern comes into the picture.

The Decorator Pattern is commonly used to modify or add additional behaviour to a class dynamically without modifying it’s current behavior.

Assuming we have an existing service, like so.

Read the rest of this entry »

Back To Basics


Today I was reading an article about software design and that got me thinking about the basics of programming. In my opinion, the root of any form of programming has everything to do with Separation of concerns (SoC). So what is separation of concerns? I would like to put it simply as SoC = Encapsulation + Abstraction + Decoupling.

Read the rest of this entry »