Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.factorymethod
Class EvilSequenceCommandCreator<E>

java.lang.Object
  extended by dk.rode.thesis.factorymethod.CommandCreator<E,Sequence.State>
      extended by dk.rode.thesis.factorymethod.SequenceCommandCreator<E>
          extended by dk.rode.thesis.factorymethod.EvilSequenceCommandCreator<E>
Type Parameters:
E - The type of values delivered by created commands (and thus sequences).

@Participant(value="ConcreteCreator")
public class EvilSequenceCommandCreator<E>
extends SequenceCommandCreator<E>

An evil sequence command creator is a test creator that flips the functionality offered by the sequence command creator, and may decide to return a new evil command as a default command.

This creator can create the following commands based on the supplied internal sequence state:

Notice that the regular commands are flipped based on the supplied state!

An evil sequence command creator is stateless and thread-safe.

Implementation notes:
By throwing exceptions in the factory methods, we test the full functionality of the CommandCreator.getCommand(Sequence, Object) method.

Author:
Gunni Rode / rode.dk

Constructor Summary
EvilSequenceCommandCreator()
          No-arg constructor.
 
Method Summary
protected  Command<E> create(Sequence<E> sequence, Sequence.State state)
          Factory method to create a new command of the type specified by the token supplied as token.
protected  EvilCommand<E> createDefault(Sequence<E> sequence)
          Factory method to create a new default command in case the normal command creation failed.
 
Methods inherited from class dk.rode.thesis.factorymethod.CommandCreator
equals, getCommand, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EvilSequenceCommandCreator

public EvilSequenceCommandCreator()
No-arg constructor.

Method Detail

create

protected Command<E> create(Sequence<E> sequence,
                            Sequence.State state)
                     throws Exception
Description copied from class: CommandCreator
Factory method to create a new command of the type specified by the token supplied as token.

The sequence set as the receiver is supplied as sequence.

Overrides:
create in class SequenceCommandCreator<E>
Parameters:
sequence - The sequence; never null.
state - The token identifying the type of command to create; can be null.
Returns:
The corresponding command, or null if no such command could be created. If null is returned, a default (on null) command is returned by CommandCreator.getCommand(Sequence, Object).
Throws:
Exception - If the creation fails; if so, a default (or null) command will be returned by getCommand.
See Also:
CommandCreator.createDefault(Sequence)

createDefault

protected EvilCommand<E> createDefault(Sequence<E> sequence)
                                throws Exception
Description copied from class: CommandCreator
Factory method to create a new default command in case the normal command creation failed.

Overrides:
createDefault in class CommandCreator<E,Sequence.State>
Parameters:
sequence - The sequence; never null.
Returns:
A new default command; if null is returned, a null command is returned by CommandCreator.getCommand(Sequence, Object). This implementation returns a new NullCommand.
Throws:
Exception - If the creation fails; if so, a null command will be returned by getCommand.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.