Welcome to the Design Pattern for Beginners article series. Thanks to all, special thanks to those who were with us from the beginning. If you are new to this series then I suggest you go through all the previous articles.
- Design Pattern For Beginners - Part 1: Singleton Design Pattern
- Design Pattern For Beginners - Part 2: Factory Design Pattern
- Design Pattern For Beginners - Part 3: Prototype Design Pattern
- Design Pattern For Beginners - Part 4: Decorator Design Pattern
- Design Pattern For Beginners - Part 5: Composite Design Pattern
- Design Pattern For Beginners - Part 6: Adaptor Design Pattern
- Design Pattern For Beginners - Part 7: Bridge Design Pattern
- Design Pattern For Beginners - Part 8: memento Design Pattern
- Design Pattern for Beginners - Part-9: Strategy Design Pattern
- Design Pattern for Beginners - Part-10: Observer Design Pattern
In this article we will learn how to implement the Implement Decouple Architecture in applications. Decoupling is very important in application development. It helps up to attach and detach components of any class without affecting another class.
The main goal of decoupling is to reduce dependency. Let's use an example to understand the concept. Think about a Desktop computer. If the monitor does not work then we just unplug it and replace it with a new one, even a different brand would work.
If the hard disk does not work then we just unplug it (hope you know how to unplug it! Ha ..Ha) and install a new one. Now, think of how to decouple each and every component? When we are changing one, it does not at all affect other components and the computer is running happily.
Now, our purpose is to implement the same kind of concept in software development. OK, one thing has been forgotten for explanation, tight coupling. Yes, it indicates that two entities are very much dependent on each other. If we change one then it will definitely effect another one.
OK, no more discussion. Let's implement the concept of decoupling.
How to implement?
Hmm…, one big question is, how to implement it? The solution is an interface. As the name suggests, it will be in the middle of two classes.
How it will come?
Let's see with an example. Here we will communicate with two classes using an interface.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace InterfaceService
- {
- public interface IService
- {
- void Serve();
- }
- public class Server : IService
- {
- public void Serve()
- {
- Console.WriteLine("Server executes");
- }
- }
- public class Consumer
- {
- IService obj;
- public Consumer(IService temp)
- {
- this.obj = temp;
- }
- public void Execute()
- {
- obj.Serve();
- }
- }
- }


kieth biasilloPosted Dec 11, 2019, 10:43 AM
This is simply a Dependency Injection pattern. Not sure if you didn't have a name for it back then, but this is what it is called now. Excellent description though.
Sam HobbsPosted Sep 18, 2013, 12:21 PM
I still do not understand what an "Implement Decouple Architecture" is. Note that in the example of a hard drive, normally we would need to restore the data from the old drive to he new drive. Is that relevant to what you are describing?