Creational Patterns (v1)

Creational Patterns (v1) - Object-Oriented Design...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Object-Oriented Design Creational Patterns George Blankenship 1 CSCI 253 Creational Patterns George Blankenship 1 Object Oriented Design: Creational Patterns George Blankenship Overview Creational Patterns Singleton Abstract factory Factory Method Pt t Structural Patterns Composite Façade Proxy Behavioral Patterns Chain of Respons. Command Interpreter Creational Patterns George Blankenship Prototype Builder Flyweight Adapter Bridge Decorator Iterator Mediator Memento Observer State Strategy Template Method Visitor The Elements of a Design Pattern • The pattern name • The problem that the pattern solves – Including conditions for the pattern to be applicable • The solution to the problem brought by the pattern Creational Patterns George Blankenship 3 – The elements (classes-objects) involved, their roles, responsibilities, relationships and collaborations – Not a particular concrete design or implementation • The consequences of applying the pattern – Time and space trade off – Language and implementation issues
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object-Oriented Design Creational Patterns George Blankenship 2 The Singleton Pattern: The Problem Ensure that a class has exactly one instance and provide a global point of access to it - There can be only one print spooler, one Monopoly Board Creational Patterns George Blankenship 4 file system, one window manager in a standard application - There is only one game board in a monopoly game; one maze in a maze-game : Monopoly Board : Monopoly Board The Singleton Pattern Participant & Collaboration • Participant: • Singleton: – is responsible for creating and storing its own unique instance Creational Patterns George Blankenship 5 – defines an Instance operation that lets clients access its unique instance • Collaboration: – the “class level” Instance operation will either return or create and return the sole instance; a “class level” attribute will contain either a default indicating there is no instance yet or the sole instance Control Unique Existance Creational Patterns George Blankenship 6
Background image of page 2
Object-Oriented Design Creational Patterns George Blankenship 3 Exception Definition class SingletonException extends RuntimeException { // new exception type for singleton classe Creational Patterns George Blankenship 7 // new exception type for singleton classes public SingletonException() {super();} // new exception type with description public SingletonException(String s) {super(s);} } PrintSpooler Class class PrintSpooler { //this is a prototype for a printer-spooler class //such that only one instance can ever exist static boolean instance_flag=false; //true if 1 instance public PrintSpooler() throws SingletonException { if (instance_flag) throw new SingletonException("Only one spooler allowed"); Creational Patterns George Blankenship 8 throw new SingletonException( Only one spooler allowed );
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 21

Creational Patterns (v1) - Object-Oriented Design...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online