Issue #9: DotNet (.NET)
Ahmed Tarek Hasan
Senior Software Design Engineer @ASML (Advanced Semiconductor Material Lithography) | Technical Blogger | Development Simply Put (DevelopmentSimplyPut.com)
This issue would be about some?topics for DotNet (.NET)?developers.
Notes:
When Implementations Affect Abstractions
If you ask a developer if the knowledge of the available implementations could affect his abstractions design, most probably he would say:
No, if this happens then my knowledge of the system is not enough for designing the abstractions.
At some point on my career as a Software Engineer, I would have agreed with this. Actually, I would have provided the same answer if someone asked me the same question.
However, on more than one occasion I came across some solutions which made me change my mind on this.
Long story short, yes, you need to understand your system and the capabilities that should be provided by each module to be able to design your abstractions.?However, this is not enough.
Exploring some of the possible implementations could help you enhance your abstractions.
Ok, let’s say that your knowledge of the system you are designing and all its interactions is a part of your job and you actually need it to do your job.?However, being creative about building this knowledge is something else.
What we are discussing now is how to build this knowledge. One of the best and creative ways is that once you have an abstraction in mind, you try to explore the possible implementations. This would put your mind in an effective state that would help you link too many loose ends.
Mediator Design Pattern In .NET C#
The?Mediator Design Pattern?is one of the behavioral design patterns.
领英推荐
According to?Wikipedia, the definition is as follows:
The essence of the Mediator Pattern is to “define an object that encapsulates how a set of objects interact”. It promotes loose coupling by keeping objects from referring to each other explicitly, and it allows their interaction to be varied independently. Client classes can use the mediator to send messages to other clients, and can receive messages from other clients via an event on the mediator class.
Therefore, to put it in simple words, the?Mediator Design Pattern?is used to manage the interactions between group of objects (similar or not) keeping the the objects isolated from each other.
To understand this, let me explain more with a simple example.
Let’s say that you are implementing a Chat Room. So, you have unlimited number of users who can join the room and once any user sends a message, the message should be received by all other users on the Chat Room.
So, implementing this, you would have a?User?class with?SendMessage?method.
However, you still need to have access to the other Users so that you can direct your the message to them. Also, whenever, a User leaves the Chat Room, you would also need to remove this User from all other Users so that they don’t send a message to him.
You have more than one way to achieve this:
The first option would work, but, it is not good because:
Now, if we explore the second option:
As you can see, it would be better to go with the second option. Now, let me tell you that what you are going to implement in the second option is the?Mediator Design Pattern.
That’s it, hope you find reading this newsletter as interesting as I found writing it ??