

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























Dr. Michael Eichberg Software Engineering Department of Computer Science Technische Universität Darmstadt
The GoF Design Patterns | Example / Motivation 2 Let’s assume we want to develop a framework for applications that can present multiple documents to the user (MDI style). We want to support a wide variety of applications: ▶Text editors ▶Word processors ▶Vector drawing applications ▶Document Viewers ▶... Our framework should - in particular - be able to manage the documents.
The GoF Design Patterns | Example / Motivation - Common functionality for handling documents 4 Nisus Writer Pro TextMate
The GoF Design Patterns | Intent 5 Define an interface for creating an object, but let subclasses decide which class to instantiate. (Factory Method lets a class defer instantiation to subclasses.)
The GoF Design Patterns | Example / Motivation - Implementation of an Application Using the Framework 7 public class TextDocument extends Document { … // implementation of the abstract methods } public class MyApplication extends Application { public Document createDocument() { return new TextDocument(); } }
The GoF Design Patterns | Example / Motivation - Class Diagram of an Application Using the Framework 8 open() close() save() Document TextDocument createDocument() newDocument() Application createDocument() MyApplication docs
The GoF Design Patterns | Participants 10
The GoF Design Patterns | Consequences (I) 11
The GoF Design Patterns | Implementation 13 Two major variants:
The GoF Design Patterns | Implementation - Parameterized factory methods 14
public abstract class Creator { public abstract Product createProduct(ProductId pid); }
public abstract class Application { public abstract Document createDocument(Type e); } public class MyApplication extends Application { public Document createDocument(Type e){ switch(e) { case Type.JPEG : return new JPEGDocument(); case Type.PDF : return new PDFDocument(); } } }
Placeholder | Related Patterns
Dr. Michael Eichberg Software Engineering Department of Computer Science Technische Universität Darmstadt
The GoF Design Patterns | The Abstract Factory Method Design Pattern Motivation / Example Scenario 19 Our goal is to support different databases. Requirements: ▶The application should support several databases (We want to be able to change the database at startup time.) ▶We want to support further databases (We want to make the implementation unaware of the specific database(s).)
Excursion | Supporting Variety A result set enables the iteration over the result of an SQL query. 20 How to provide an interface to all of these different kinds of ResultSets? MySQLResultSet DB2ResultSet FirebirdResultSet MsSQLResultSet OracleResultSet