Presentation is loading. Please wait.

Presentation is loading. Please wait.

JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access.

Similar presentations


Presentation on theme: "JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access."— Presentation transcript:

1 JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access Patterns

2 JDBC Session 4 What are Design Patterns? A design pattern is a repeatable and proven solution to a particular problem. The notion of the design pattern did not originate in the software development field. Software development patterns were identified in the now classic text: Elements of Reusable Object-Oriented Design. Intro To Design Patterns (p. 1)

3 JDBC Session 4 Characteristics of Design Patterns Design patterns are discovered and refined, not invented. They are repeatable solutions that can be used across multiple applications and contexts. They represent industry best practices. They are technology-independent. Intro To Design Patterns (p. 2)

4 JDBC Session 4 You’re already familiar with the patterns we study tonight! The Factory Pattern - simply glorified polymorphism - the “is a” relationship The Façade Pattern - simply glorified composition - the “has a” relationship Intro To Design Patterns (p. 3)

5 JDBC Session 4 We see the Factory pattern or class again & again in OO programs A Factory pattern is one that returns an instance of one of several possible classes depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods. Each class returned by the Factory performs the required task differently and is optimized for different kinds of data. The Factory Pattern (p. 1)

6 JDBC Session 4 How a Factory Works: In this figure, x is a base class and classes xy and xz are derived from it. The Factory is a class that decides which of these subclasses to return depending on the arguments you give it. On the right, we define a getClass method to be one that passes in some value abc, and that returns some instance of the class x. Which one it returns doesn't matter to the programmer since they all have the same methods, but different implementations. How it decides which one to return is entirely up to the factory. It could be a very complex function but it is often quite simple. The Factory Pattern (p. 2)

7 JDBC Session 4 Example on Web Site: Lessons / JDBC / JDBC Session 4 / Namer The Factory Pattern (p. 3)

8 JDBC Session 4 When to Use a Factory Pattern: A class can’t anticipate which kind of class of objects it must create. A class uses its subclasses to specify which objects it creates. You want to localize the knowledge of which class gets created. There are several variations on the factory pattern to recognize: The base class is abstract and the pattern must return a complete working class. The base class contains default methods and is only subclassed for cases where the default methods are insufficient. Parameters are passed to the factory telling it which of several class types to return. The classes may share the same method names but do something quite different. The Factory Pattern (p. 4)

9 JDBC Session 4 Thought Lab: 1.Consider a personal checkbook management program like Quicken. It manages several bank accounts and investments and can handle your bill paying. Where could you use a Factory pattern in designing a program like that? 2.Suppose are writing a program to assist homeowners in designing additions to their houses. What objects might a Factory be used to produce? The Factory Pattern (p. 5)

10 JDBC Session 4 The Façade Pattern defines a higher-level interface to a set of classes & interfaces in a subsystem, thus making the complex subsystem easier to use. The Façade pattern shields clients from complex subsystem components and provides a simpler programming interface for the general user. However, it does not prevent the advanced user from going to the deeper, more complex classes when necessary. A façade object provides a single, simplified interface to the more general facilities of a subsystem. The Façade Pattern (p. 1)

11 JDBC Session 4 How a Façade Works: The Façade Pattern (p. 2)

12 JDBC Session 4 Examples on Web Site: Lessons / JDBC / Session 4 / CuppaTea Lessons / JDBC / Session 4 / JDBC Facade The Façade Pattern (p. 3)

13 JDBC Session 4 When to Use a Façade Pattern: To provide a simple interface to a complex subsystem. This interface is good enough for most clients; more sophisticated clients can look beyond the facade. To decouple the classes of the subsystem from its clients and other subsystems, thereby promoting subsystem independence and portability. The Façade Pattern (p. 4)

14 JDBC Session 4 Benefits of the Façade Pattern: It hides the implementation of the subsystem from clients, making the subsystem easier to use. It promotes weak coupling between the subsystem and its clients. This allows you to change the classes the comprise the subsystem without affecting the clients. It reduces compilation dependencies in large software systems. It simplifies porting systems to other platforms, because it's less likely that building one subsystem requires building all others. It does not prevent sophisticated clients form accessing the underlying classes. Note that Facade does not add any functionality, it just simplifies interfaces. The Façade Pattern (p. 5)


Download ppt "JDBC Session 4 Tonight: Design Patterns 1.Introduction To Design Patterns 2.The Factory Pattern 3.The Facade Pattern Thursday & Next Tuesday: Data Access."

Similar presentations


Ads by Google