up previous next contents
Next: Agile Methods Up: A sample process Previous: Addressing Requirements   Contents

Subsections

Survey of Design Patterns

  • Repeating patterns - ``Her garden is like mine, except that in mine I use astilbe.''
  • Recurring solutions to design problems you see over and over.
  • A set of rules describing how to accomplish certain tasks in the realm of software development.
  • Made famous by the text ``Design Patterns'', by Gamma, Helm, et al.
  • A list of some of the most well-known design patterns:
    Factory Abstract Factory
    Singleton Builder
    Prototype Adapter
    Bridge Composite
    Decorator Facade
    Flyweight Proxy
    Chain of Responsibility Command
    Interpreter Iterator
    Mediator Memento
    Observer State
    Strategy Template
    Visitor

Factory pattern example

  • The code and diagram that follow demonstrate a small, simple example of the Factory pattern

    public abstract class Dog {
      public abstract void speak ();
    }
    
    public class Poodle extends Dog {
      public void speak() {
        System.out.println("The poodle says \"arf\"");
      }
    }
    
    public class SiberianHusky extends Dog {
      public void speak() {
        System.out.println("The husky says \"Whazzup?!!\"");
      }
    }
    
    public class Rottweiler extends Dog {
      public void speak() {
        System.out.println("The Rottweiler says (in a very deep voice) \"WOOF!\"");
      }
    }
    

    public class Main {
      public Main() {
        // create a small dog
        Dog dog = DogFactory.getDog("small");
        dog.speak();
    
        // create a big dog
        dog = DogFactory.getDog("big");
        dog.speak();
    
        // create a working dog
        dog = DogFactory.getDog("working");
        dog.speak();
      }
    
      public static void main(String[] args) {
        new Main();
      }
    }
    

    public class DogFactory {
    
      public static Dog getDog(String criteria) {
        if ( criteria.equals("small") )
          return new Poodle();
        else if ( criteria.equals("big") )
          return new Rottweiler();
        else if ( criteria.equals("working") )
          return new SiberianHusky();
    
        return null;
      }
    }
    

.

Figure 1.11: A UML use case diagram for the DogFactory.
POOP3


up previous next contents
Next: Agile Methods Up: A sample process Previous: Addressing Requirements   Contents