SE450: Lecture 7 (Creational Patterns)

Contents [0/12]

Overview [1/12]
Midterm Results [2/12]
Homework Solution [3/12]
Martin's principles [4/12]
Creational Patterns [5/12]
Creational Patterns: Static Factory [6/12]
Creational Patterns: Singleton [7/12]
Creational Patterns: Prototype [8/12]
Creational Patterns: Factory [9/12]
Creational Patterns: Abstract Factory [10/12]
Creational Patterns: Factory Method [11/12]
Creational Patterns: Builder [12/12]

Overview [1/12]

Midterm

Homework Solution

Martin's Principles

Creational Patterns

Midterm Results [2/12]

You may keep your exams, but I won't be posting solutions, just going over results in class

Homework Solution [3/12]

Homework files are here

Martin's principles [4/12]

Martin's principles are highlighted in the paper Design Principles and Design Patterns at his website, www.objectmentor.com. This site is an excellent resource on OO programming, XP, and design techniques.

The Open/Closed Principle: Software entities (classes, modules, etc) should be open for extension, but closed for modification. Abstraction is the key to this principle. This is possible through dynamic polymorphism.

The Liskov Substitution Principle: Derived classes must be usable through the base class interface without the need for the user to know the difference. This implies:

Violations of LSP are latent violations of OCP

The Dependency Inversion Principle: Details should depend upon abstractions. Abstractions should not depend upon details (concretions). Dependencies between classes should target interfaces or abstract classes. This provides flexibility to the design. This keeps you from depending on volatile modules.

The Interface Segregation Principle: Many client specific interfaces are better than one general purpose interface

The Reuse/Release Equivalency Principle: The granule of reuse is the same as the granule of release. Only components that are released through a tracking system can be effectively reused.

The Common Closure Principle: Classes that change together, belong together.

The Common Reuse Principle: Classes that aren't reused together should not be grouped together.

The Acyclic Dependencies Principle: The dependency structure for released components must be a directed acyclic graph. There can be no cycles.

The Stable Dependencies Principle: Dependencies between released categories must run in the direction of stability. The dependee must be more stable than the depender.

The Stable Abstractions Principle: The more stable a class category is, the more it must consist of abstract classes. A completely stable category should consist of nothing but abstract classes.

Creational Patterns [5/12]

Purpose
Creational Structural Behavioral
Scope Class Factory Method (107) Adapter (class) (139) Interpreter (243)
Template Method (325)
Object Abstract Factory (87)
Builder (97)
Prototype (117)
Singleton (127)
Adapter (object) (139)
Bridge (151)
Composite (163)
Decorator (175)
Facade (185)
Flyweight (195)
Proxy (207)
Chain of Responsibility (223)
Command (233)
Iterator (257)
Mediator (273)
Memento (283)
Observer (293)
State (305)
Strategy (315)
Visitor (331)

Creational Patterns: Static Factory [6/12]

Normally, how do you create an instance of a class?

However, you can write your own method to instantiate a class. This is not one of the GoF patterns, but is documented in Joshua Bloch's Effective Java.
Benefits: Static Factory methods...

Disadvantages:

Convention:

A good example of a static factory is in the Java APIs. For example, in Boolean:

public static Boolean valueOf(boolean b) {
       return (b ? Boolean.TRUE: Boolean.FALSE);
}
Somewhere in the Boolean class, there is code like this:
public static Boolean TRUE = new Boolean(true);

public static Boolean FALSE = new Boolean(false);

Creational Patterns: Singleton [7/12]

Creational Patterns: Prototype [8/12]

Creational Patterns: Factory [9/12]

Creational Patterns: Abstract Factory [10/12]

Creational Patterns: Factory Method [11/12]

Creational Patterns: Builder [12/12]


Revised: 2003/2/16