C# · CodeProject · Dotnet

Structural Design Pattern (Part 2)

Dear Reader,

Previously i had published/wrote blog post on Design Pattern presentation where in i gave away a link to my slideshare ppt about this topic. I am glad to say that many people have liked the ppt and have requested to write-up an in detailed about the same ppt. Please go through my first post if you have not.

Note: Let me warn you that these couple of posts what i am going to write will be lengthy ones, so read it if you have time.

Ok then amigo, lets start.

In this article i shall be talking mainly about few Structural Design patterns as it is in the slides. Now if you are referring to the PPT, then i have picked 4 structural patterns viz. Adapter, Bridge, Decorator and Facade. Ofcourse they are not the best but not the simplest either :), so in this article i shall try to recall and explain to my best capabilities the same way as i did while giving this presentation to my team months ago.

Let me start off by saying that Design Patterns are not the answer for every problem, but rather solution to specific problems. In other words, normally i have seen developers who start off to learn Design pattern happen to get crazy/obsessed over it and thus start to use it extensively in their production code. Hey, you’re not alone buddy even I was the same.

Although patterns do help us in a great deal, but still they have their down sides too. Although many experts argue that design patterns are big draw back or failure in software programming as it induces many problems. Well i wont be talking about it in this posts nor I am that expert. So it is recommended that to not extensively make use of Patterns where ever you see a code smell. If there is a simple flexible solution, then it is suggested to use that rather than patterns. I remember once my ex-colleague was saying that too much use of patterns is like putting yourself into haywire condition or even perhaps hanging yourself.

Well then, we know that Design patterns are broadly categorized into 3 parts viz Structural, Behavioral and Recreational. Since this article is only w.r.t Structural, so I am going to stick with it.

Let me get in detail about this category and 4 patterns i have picked to talk about. I shall explain as how i always question myself in learning a topic. Hope you shall like it. Basically i shall ask myself 4 basic questions: What, Why, How and Where.

Structural Patterns:

What:

This category of pattern shall talk or defines the composition between the modules or components or even entities which allows us to develop or build great larger systems. As the name says, it defines how each component or entity should be structured so as to have a very flexible inter connecting modules which can co-work together in a larger system.

Many a times it so happens that fitting modules or components in a system which may be new or an existing one seems a tedious job. Or even at times where in many different components have to co-work together in a well mannered way to achieve the final structure.

Why:

This patterns allows us to build or develop module and fit them appropriately or even make them work coherently and comfortably among other modules which further helps in understanding relationships between objects and classes. With out this category of patterns, one would have to change a lot of stuffs around to fit in a module. Hence to avoid this re-work or clumsy work around, this pattern is used.

Let me show you my visualized image of an complex system as per the image below:

As you can see form the above image, if i assume those the objects/modules which are quite different in their own nature due to its behavior and responsibilities given to it. Now looking at the above picture, its pretty sure that nothing is organized properly. That means that the structure of the whole complex system is very messy.

If you want to add a new object type (a round shaped object perhaps?) or a module into this system and build up a communication with others, imagine how difficult it is. Not only its very tedious job, you either will create more objects/modules to accommodate this new object/module or you modify existing objects to fit the new one, thus you might break some things, which involves in testing every test case on the system to check its consistency.

So upon using this Structural patterns, you can change the structure of system to some thing like shown below:

As you can see from the above image, i have applied many different structural patterns to organize the structure in more of a logical group. Now this way, you can easily analyze the structure of the system as well as its communication aspect too. Now changing/adding any thing to this more organized structure is not that difficult job.

Note: The above representation image is just for understanding sake on the topic. This is in no way any UML or similar representation.

How:

As said earlier, i have picked following patterns among lot more:

  1. Adapter
  2. Decorator
  3. Bridge
  4. Facade

Where:

This depends on each of the patterns which fall under this category, so please read each one of those in my blog posts.

Let me end this Part 2 article here itself, such that it wont be a very long one which might bore you off. Please look forward for Part 3, 4, and 5 or even more it really depends on how long each posts goes.

Thanks for reading 🙂

P.S: Your valuable comments for my learning is well appreciated.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s