Eclipse Design Patterns – Strategy in SWT

Design patterns used in SWT is relatively straightforward. SWT is an independent module in Eclipse platform.

eclipse-platform-swt

In brief, Strategy let client dynamically set the strategy it should use. Strategy is different from State. First of all, Strategy is simpler since it is only about using interface instead of concrete class. Secondly, State involves changing the state for a given context. For more information, go to State pattern or Strategy pattern tutorial.

In this following example, A RowLayout is created as one strategy to setup Shell’s layout. The shell simply set it’s layout strategy to be RowLayOut.

RowLayout rowLayOut = new RowLayout()
Shell shell = new Shell();
shell.setLayout(rowLayOut);

Leave a Comment