Skip to content

Month: January 2017

Behavioral Design Pattern: Chain of Responsibility Pattern

Chain of Responsibility Pattern will be our first Behavioral Design Pattern. Behavioral Design Patterns solves communication problem between different modules. They increase the flexibility in the communication process between Objects. Chain of responsibility pattern is a pretty simple pattern. It requires creation of a chain of processing objects that can process any provided task. Whenever a task needs to be done code does not relay on writing complex if..else… ladder to pass which processor needs to process which task. Task will be passed to a pipeline where each process resides and reads the inputted task one by one. Each processor has a fixed responsibility and as soon as the processor encounters any task that it can handle it will handle it otherwise it will pass the task to the next handler or processor.

Java Concurrency Basics

By using Multi-threading or concurrency we can enhance any Program’s performance in a great way. However multi-threading comes with it’s own challenges. Multi-threaded application runs all its thread in the same memory space thereby creating synchronization issues as reading and written of the same memory space is possible. For example, assume that when one thread running on one CPU Core is trying to read a memory location while another thread running on different CPU Core is trying to write it. What will happen now? Which value will the first thread read? Can it read both values partially?

Creational Design Pattern: Prototype Pattern

Prototype Pattern is an creation pattern based on cloning a pre-configured object. The idea is that you pick an object that is configured for either the default or in the ballpark of some specific use case and then you clone this and configure to your exact needs. The pattern is useful to remove a bunch of boilerplate code, when the configuration required would be onerous. We can think of Prototypes as a preset object, where you save a bunch of state as a new starting point.