Quantcast
Channel: SPEC INDIA » Process
Viewing all articles
Browse latest Browse all 10

Design Pattern in .Net – Introduction

0
0

Welcome to the series of blogs on Design Patterns. This is introductory blog on design pattern. In this blog I will try to explain definition of design pattern & will try to walkthrough of 3 main categories of design pattern.

Definition:

Design patterns are tried and tested programs for recurring problems in software programming. These patterns are documented from experience gain from IT industry.

Design patterns are documented best practices for software architecture.

Design pattern is not silver bullet. Many times we have questions that how can we implement design patterns in the project.

My answer to the question is – “You know your project well. Every project is different. Issues are different. Way of approach is different. So take up the design pattern as reference, look into your project problem and try to solve using design pattern.

Understand important fact that “Patterns are for project, project is not for pattern”.

I have seen many times developers are trying to force design patterns in project & it completely masses up the software architecture.

Design patterns are in existence from the long time back.

Even in college time, when it was asked to build sorting algorithm the first answer is “Bubble Sort” pattern. Even though Bubble Sort is there, many times you should use your own algorithm because you know the problem well so don’t try to fit bubble sort if it is not matching your sorting requirement & use your customize algorithm to simplify the project.

Design patterns are mainly classified in 3 categories.

  1. Creational Patterns
  2. Structural Patterns
  3. Behavioral Patterns

Creational Patterns

When we look at software architecture, one of the big issues in the software architecture is:

How do we control the object creation?

How do we centralize object creation?

Let us say you have 100 of classes in your project & you client code starts creating object.

E.g. Inventory object, Account Object, Order Object.

Client code is creating, closing & destroying the objects.

In such events,

  1. Client code becomes very complicated.
  2. Client code is very much heavily tied up with main concrete objects

This leads to heavy coupling with client code & main concrete objects. In order to solve this problem we have creation pattern.

In Creation pattern, we centralize or delegate object creation in different class & this class will be used by client code to get objects.

Structural Patterns

A second big issue in the software architecture is to manage structural changes.

E.g. We have Employee class & Phones Class. One employee can have multiple phones. Phone class is aggregated inside the Employee class.

This is the working structure of your project & suddenly your client sends a request saying that Phone & Employee should be independent entity. Here you want to make a structure change but you also want to see that it does affect throughout the project. Here the structure Patterns will come in to the picture.

Behavioral Patterns

Sometimes you want to change behavior of class and make sure that it will not affect the project.

E.g. we have Product class and when you place order we are checking validity period of product and it is 20 days. Now we need to change the behavior of the class and say that it is now 2 months. There is change in behavior of the class but we have to ensure that it does not affect project a lot. It just changes exact place where we need to change or exact entity which we need to change.

All software architecture design issues in line with these three categories. All 3 categories are addressed in design pattern by approx. 40 design patterns.

In coming article we will go through each design pattern and will try to understand each one of them in detail.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images