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...
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...