Skip to main content

Posts

Design Patterns for better code - Mediator Design Pattern

The mediator design pattern comes under the list of Behavioral design patterns. The mediator facilitates the communication b/w different objects so they don't have to keep the reference of each other. instead, they depend on a mediator to communicate with the other objects. Definition of Mediator Design Pattern : With the mediator pattern, communication between objects is encapsulated within a mediator object. Objects no longer communicate directly with each other, but instead, communicate through the mediator. This reduces the dependencies between communicating objects, thereby reducing coupling. Let's take the example of a Chat Room. One Chat Room can have multiple Team members and each message sent by any of the members will be broadcasted to all the other members. Let's say, If a Member has to send a message to Other Members it would required to have instances of all the other Team Members. You can think of this idea already, what a mes...
Recent posts

Design Patterns for better code - Null Object Design Pattern

Null being a part of programming languages is a billion dollar mistake. -Tony Hoare Writing everyday code irrespective of Language used (either be C# or Java or Python) we write null checks. Well we write null checks so often that a study estimates on an average one developer gives 5% of his entire development time to null checks only. So we can think of the importance of null checks. It's also the main problem of production issues specially for Junior developers.  Well writing null checks is not a problem until 100 lines of code contains 20 lines of null check code 😀 To reduce the number of lines for null checks, so that developer only focus on business logic instead of null check, Null Object design pattern was invented. Let's look at how we can use Null Object Design Pattern for our Invoice Application. Here we have different types of Invoice logic written in Separate Invoice classes (EmailInvoice, PDFInvoice, SMSInvoice). The User will choose the Invoice Type at runti...

Design Patterns for better code - Singleton Design Pattern C#

 Singleton Design pattern is also a good design pattern. Although in current world we use dependency injection heavily, so we rely on Dependency provider library (IOC container) for providing us the variable of Singleton scope. Let's just dig straight into what is Singleton. Sometimes there are requirements to have only single instance of a class through out the life-cycle of an application (Like if we are using a printer service and multiple users are using it. Than we want only one instance of that service through out the application life-cycle. So that it's only accessible to one thread at any point of time).  Here are few characteristics of Singleton Design Pattern: At any time only one or no instance of Singleton class will exist. Singleton classes are created without parameters. (Because it contains single, private, parameter-less constructor) Lazy instantiation is default in Singleton Design Pattern. Singleton cl...

Design Patterns for better code - Strategy Design Pattern C#

Strategy design pattern is the most easiest pattern out of all the design patterns and certainly the most useful one. There are high chances that you have written this type of code in your application but you wasn't aware if this thing have a name. But identifying certain types of code solutions with their name helps us to discuss those solutions with your team mates. It provides a common language to discuss these solutions. If you have identified some area in your code which can be simplified using Strategy design pattern and you want to ask your team mate to do so, It's easy to ask them to implement Strategy design pattern there instead of explaining them (Well you should create an Interface for this and than create two classes which implements this interface and than select the implementations at run time). Well you can guess which one was easier to convey :). I will not be using any of the complex UML diagrams explained by Gangs of Four to c...

Event-Engine Framework, Dynamics Code Better

Hallo, I am Naveen. A full-time solution designer & developer for Microsoft applications (SAS & Custom software development). This blog post is for Dynamics CRM solutions enthusiasts, to solve one of the biggest problems in their development life cycle (Code Management). Well the solution explained in this post solve back-end code management problem only for Plugins, but sooner, I will come up with something for front-end as well. Microsoft Dynamics CRM was originally developed for building applications that range from Sales, Marketing to Customer Service. But nowadays it's not just limited to these applications, It's being used to build a variety of applications, that include back-end system for small industry to highly scalable system of an Enterprise business.At first glance Dynamics CRM may looks a no-code solution to develop, but it's not. For developing enterprise grade solutions we have to rely on C# code to stuff all our business logic. So it's ...