Eclipse Design Patterns – Composite in Workspace

Composite in Workspace Composite pattern defines a tree hierarchy which lets clients treat objects in the hierarchy uniformly. In Eclipse Workspace, IWorkspace is the root interface and it is a Composite of IContainers and IFiles. Here is the interface hierarchy diagram. Code Example Here is an example to show how to get projects under Workspace. … Read more

Eclipse Design Patterns – Proxy and Bridge in Workspace

1. Proxy and Bridge pattern in Core Workspace The most important design patterns used in Core Workspace is called “Proxy and Bridge”. The most confusing question is about which part is proxy or which part is bridge. The following diagram use IResource for demonstration, others are similar such as IFile, IFolder, IProject, IWorkspaceRoot, etc. In … Read more

Java Design Pattern: Template Method

The Template Method design pattern defines the workflow for achieving a specific operation. It allows the subclasses to modify certain steps without changing the workflow’s structure. The following example shows how Template Method pattern works. Class diagram Java Code Vehicle.java defines a vehicle and hot it works package com.programcreek.designpatterns.templatemethod;   abstract public class Vehicle { … Read more

Java Design Pattern: Decorator – Decorate your girlfriend

Decorator pattern adds additional features to an existing object dynamically. In this post, I will use a simple example – decorate your girlfriend – to illustrate how decorator pattern works. 1. Decorator Pattern Story Let’s assume you are looking for a girlfriend. There are girls from different countries such as America, China, Japan, France, etc. … Read more

Java Design Pattern: Bridge

In brief, Bridge Design Pattern is a two layer abstraction. The bridge pattern is meant to “decouple an abstraction from its implementation so that the two can vary independently”. The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes. 1. Bridge pattern story The example of TV and Remote Control(typo … Read more

Java Design Pattern: Adapter

Adapter pattern is frequently used in modern Java frameworks. It comes into place when you want to use an existing class, and its interface does not match the one you need, or you want to create a reusable class that cooperates with unrelated classes with incompatible interfaces. 1. Adapter pattern story The Adapter idea can … Read more

Design Patterns Used in Eclipse Platform

Here I summarize the design patterns used in Eclipse platform. Understanding design patterns used in Eclipse is the key for understanding Eclipse platform. Eclipse architecture has a clear layered structure. Each layer is independent to each other but interactive with each other. To better understand a framework, it is a good idea to start from … Read more

Java Design Pattern: Singleton

Singleton pattern is one of the most commonly used patterns in Java. It is used to control the number of objects created by preventing external instantiation and modification. This concept can be generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects, … Read more

Java Design Pattern: Observer

In brief, Observer Pattern = publisher + subscriber. Observer pattern has been used in GUI action listener. Swing GUI example shows how action listener works like an observer. The following is a typical example about head hunter. There are two roles in this diagram – HeadHunter and JobSeeker. Job seekers subscribe to a head hunter, … Read more

Java Design Pattern Story for Proxy – A Slutty Lady

This work is translated from a foreign website which uses ancient stories to explain design patterns. 1. What is Proxy/Agent pattern? I’m too busy to response your request, so you go to my proxy. Proxy should know what the delegator can do. That is, they have the same interface. The proxy can not do the … Read more