Posts

Showing posts from March, 2018

Converter Pattern

In this post, we will discuss most commonly used  Converter Design Pattern  in Java/J2EE projects. Thanks to Java 8 features not only provides a way of generic bidirectional conversion between corresponding types but also a common way of converting a collection of objects of the same type, reducing the boilerplate code to the absolute minimum. we have written source code for this pattern using Java 8 features. Intent The purpose of the Converter Design Pattern is to provide a generic, common way of bidirectional conversion between corresponding types, allowing a clean implementation in which the types do not need to be aware of each other. Moreover, the Converter Design Pattern introduces bidirectional collection mapping, reducing a boilerplate code to a minimum. Source code The Converter Design Pattern is a behavioral design pattern which allows a common way of bidirectional conversion between corresponding types (e.g. DTO and domain representations of the logically isomor

Half-Sync/Half-Async Pattern

Image
Intent The Half-Sync/Half-Async pattern decouples synchronous I/O from asynchronous I/O in a system to simplify concurrent programming effort without degrading execution efficiency. Decompose the services of concurrent software into two separated layers�synchronous and asynchronous�and add a queueing layer to mediate communication between them. Process higher-level services, such as domain functionality, database queries, or file transfers, synchronously in separate threads or processes. Conversely, process lower-level system services, such as short-lived protocol handlers driven by interrupts from network hardware, asynchronously. If services in the synchronous layer must communicate with services in the asynchronous layer, have them exchange messages via a queuing layer. Note : Concurrent software often performs both asynchronous and synchronous service processing. Asynchrony is used to process low-level system services efficiently, synchrony to simplify application service process

Null Object Design Pattern

Image
Intent In most object-oriented languages, such as Java or C#, references may be null. These references need to be checked to ensure they are not null before invoking any methods because methods typically cannot be invoked on null references. Instead of using a null reference to convey the absence of an object (for instance, a non-existent customer), one uses an object which implements the expected interface, but whose method body is empty. The advantage of this approach over a working default implementation is that a Null Object is very predictable and has no side effects: it does nothing. Structure Participants Client  requires a collaborator. AbstractObject  declares the interface for Client's collaborator. implements default behavior for the interface common to all classes, as appropriate. RealObject defines a concrete subclass of AbstractObject whose instances provide useful behavior that Client expects. NullObject provides an interface identical to AbstractObject's so th

Memento Design Pattern

Image
Intent Without violating encapsulation, capture and externalize an objects internal state so that the object can be restored to this state later. One of the best real-life example is the text editors where we can save its data anytime and use undo to restore it to previous saved state.  Also Known As Token Structure Participants 1. Memento  This component stores internal state of the Originator object. The memento may store as much or as little of the originator's internal state as necessary at its originator's discretion. This component protects against access by objects other than the originator. Mementos have effectively two interfaces. Caretaker sees a narrow interface to the Memento�it can only pass the memento to other objects. Originator, in contrast, sees a wide interface, one that lets it access all the data necessary to restore itself to its previous state. Ideally, only the originator that produced the memento would be permitted to access the memento's internal s

Mediator Design Pattern

Image
Intent Define an object that encapsulates how a set of objects interact.Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently. Explanation Mediator design pattern is very helpful in an enterprise application where multiple objects are interacting with each other. If the objects interact with each other directly, the system components are tightly-coupled with each other that makes maintainability cost higher and not flexible to extend easily. Mediator pattern focuses on to provide a mediator between objects for communication and help in implementing lose-coupling between objects. Air traffic controller is a great example of mediator pattern where the airport control room works as a mediator for communication between different flights. Mediator works as a router between objects and it can have it�s own logic to provide a way of communication. Structure Participants 1. Mediator  This component def