Eclipse Design Patterns – Singleton in Platform

Actually this is the simplest pattern in this Eclipse Design Patterns series. The basic idea of a Singleton pattern is there is always only one instance for a target object. The following simply gives several examples from commonly used Eclipse API. Note that not all methods are from org.eclipse.core.runtime.Platform. Platform.getAdapterManager(); //only one AdapterManagerPlatform.getAdapterManager(); //only one … Read more

Java Design Pattern: Interpreter

Major revision in progress … Please come back later. Interpreter pattern is used when some context needs to be interpreted. The following example is a very simple Interpreter implementation. It interpretes letter “a” and “b” to “1” and “2”. Class Diagram Note that: the dependency is also shown in diagram to make the structure more … Read more

Java Design Pattern: Iterator

Iterator pattern is used to iterate through a collection of objects. It is a commonly used pattern, you probably have used it before. Whenever you sees something like hasNext() and next(), it is probably a iterator pattern. For example, you may iterate through a list of database query record. Iterator Pattern Class Diagram Iterator Pattern … Read more

Java Design Pattern: Flyweight

Flyweight pattern is used for minimizing memory usage. What it does is sharing as much data as possible with other similar objects. 1. Flyweight Pattern Class Diagram 2. Flyweight Pattern Java Code // Flyweight object interface interface ICoffee { public void serveCoffee(CoffeeContext context); }// Flyweight object interface interface ICoffee { public void serveCoffee(CoffeeContext context); } … Read more

Java Design Pattern: Prototype

Prototype design pattern is used when very similar objects are frequently created. Prototype pattern clones objects and set the changed feature. In this way, less resources are consumed. 1. Prototype Pattern Class Diagram 2. Prototype Pattern Java Example package designpatterns.prototype;   //prototype interface Prototype { void setSize(int x); void printSize(); }   // a concrete … Read more

Java Design Pattern: Builder

The key feature of Builder pattern is that it involves a step-by-step process to build something, i.e., every produce will follow the same process even though each step is different. In the following example, we can define a drink builder called StarbucksBuilder which will build a Starbucks drink. StarbucksBuilder has several steps to build a … Read more

Java Design Pattern: Mediator

Mediator design pattern is used to collaborate a set of colleagues. Those colleagues do not communicate with each other directly, but through the mediator. In the example below, Colleague A want to talk, and Colleague B wants to fight. When they do some action(i.e., doSomething()), they invoke mediator to do that. Mediator Class Diagram Mediator … Read more