Abstract Factory Pattern in Java

June 5, 2014

Abstract Factory pattern, another GoF pattern which falls under the category of creational design patterns, deals with a factory of factories (sometimes called a "super factory"). Main intent of this pattern is to instantiate families of related objects without exposing their concrete classes to the client and thereby reducing the complexity when dealing with large systems.

Factory Method pattern may seem quite similar to this except Abstract Factory deals with multiple families of related products where as in Factory Method pattern we have only one main product.

Basic Structure of Abstract Factory pattern



Observer Pattern in Java

June 1, 2014

When it comes to programming it is quite common to hear the terms like "Event handling and listeners". This is indeed one area where Observer design pattern is extensively used.  Observer is a GoF design pattern which falls under the category of Behavioral patterns. These types of patterns describe the process of communication between objects.

Let's take look at an example where messages are saved to a database as it receives and the user is notified whenever a new message is received. Before I learned Observer pattern, the first thing which came to mind to solve this is to monitor messages using Threads and when it comes to multi-threading things get messy but this pattern involves no threading mechanism at all.