Posts

Showing posts with the label composite

Eclipse command framework core expression : Multiple handlers

Image
Eclipse platform command framework supports core expression to control commands behavior runtime. In this series of posts I have explained different ways of using core expressions . This post explains having multiple handler for same command but activate only one of it at runtime based on some of the condition. Eclipse command framework is based on MVC framework. Command declaration, handler declaration  and contributing command to workbench helps to keep declaration separate from presentation. You can have multiple handlers for same command, but only one will be active at one moment. Core expression provides “activeWhen” declarative clause to activate specific handler for given command based on specific condition. Here is how we use it . I have created a new eclipse plug-in project. I have extended “org.eclipse.ui.editors” extension point to define two simple text editors. Here I am going to define two different handlers for same commands but only one will be active based on edito

Composite Design Pattern by example

Image
This post explains Composite design pattern with an example. When to use ? – Use Composite pattern when you have treat a collection of objects as they were once one thing. With Composite design pattern it is very easy to simplify operations over collection data structure. It reduces complexity of the code required if you were going to handle collection as special case. How to Use? - The Composite pattern consist of Component, Leaf and Composite Classes as shown below class diagram Component – Component declares the common interface that both the single and composite nodes will implements Leaf – The leaf class represent the singular atomic data type implementing he component interface.     Composite – Composite is an abstract entity which declares common functionality which are needed by concrete implementation for handling collection data. An Example -   Item.java public interface Item {     public double getPrice(); }   ColdDrink.java pu