NAVI NING

The very beginning mind itself is the most accomplished mind of true enlightenment.

Observer Pattern

Publish-subscribe model for handling one-to-many objects communication

Observer Pattern The observer pattern belongs to the behavior pattern, which focuses on the communication between objects. The observer pattern applies to a one-to-many relationship of objects, wh...

Adapter Pattern

Enable incompatible interfaces to work together

Adapter Pattern The adapter pattern is able to convert an interface into another, and let incompatible interfaces work together. It is also a structural pattern. There are two popular interface i...

Decorator Pattern

Add new functionality to a class without changing its structure

Decorator Pattern The decorator pattern enables us to add new functionality to an existing class, without changing its structure. Similar to proxy pattern, the decorator pattern is also a structur...

Proxy Pattern

Authority management of objects

Proxy Pattern The proxy pattern provides a proxy for other objects which controls the access permission of objects. Let’s look at this example, where we have a abstract class Movie and a derived c...

Factory Pattern

Simple factory, factory method and abstract factory

Factory Pattern The factory pattern is a creational pattern which encapsulates the construction of objects. In factory pattern, we do not expose the construction logic to the client directly. Inst...

Singleton Pattern

Eager singleton class and thread-safe lazy singleton class

Singleton Pattern Singleton pattern is a design pattern that restricts the instantiation of a class to one single instance. No matter how many times the objects of a singleton class are created, o...

Thread Visibility and volatile

A keyword to prevent compiler optimizations

Thread Visibility and volatile In the previous chapter we see an example of atomic operations. However, the program has a potential problem which is common in multithreaded programming which is ca...

Atomic Operations

Lock-free multithreading with atomic operations

Atomic Operations In previous chapter, we wrote a multithreaded program that sells bus tickets. We used mutual exclusion for thread synchronization. Inside the critical section, only one thread ca...

Producer-Consumer Problem

A classical thread communication mechanism

Producer-Consumer Problem In multithreaded programs, the execution order of threads is uncertain. In many situations, the execution of one thread relies on the execution of other threads. Producer...

Mutual Exclusion

Important concept to prevent race conditions

Mutual Exclusion Using what we have learnt about multithreading, we write a simple program which has three windows selling bus tickets. The total number of tickets is 100 and it takes 100 millisec...