Академический Документы
Профессиональный Документы
Культура Документы
Design Patterns
Library
Catalog of commonly used classes and methods concrete Catalog of commonly interactions between objects that developers have often found useful Theoretical/abstract Describe how objects communicate without complications of each others data models or methods
Design Pattern
Meta abstractions beyond classes and instances When possible start with interface not implementation
More important for larger systems
Hard Coding
Hard Coding
the use of an explicit value in the code or method of your program. this is hard coding 6, 3.14159 Generally considered poor programming
Debugging?
Get around with constants, parameters etc Some of you in lab 6 hard coding size, location etc
Usually one of several subclasses of a common superclass. Decision on what to return (method details) could be simple or complex
Factory Pattern II
Basically:
Create abstraction that decides which of several possible classes to return and does so (factory) Caller gets an object back
with methods in common with all other possible classes,
Abstract Factory
Implementation
Abstract base class (or better yet interface) Concrete subclass to implements interface And returns instances of subclasses of another base class. Where have we seen something like this before in this class? If we need to add more types then we can just create more classes that implement the interface and the rest of the code need not know the difference
Abstract Factory
Benefit
Isolates the concrete classes generated Actual names of classes are hidden at client level Because of this you can change (or switch among) different classes in the family (subclasses the same superclass) createButtons
The Singleton
Sometimes there should only be one instance of a particular class
Book: data base access, etc Also hardware mouse pointer etc
Must ensure that there is only one instance Single instance of class has to be globally accessible
OO Programs
Logic for program often divided into isolated, but communicating classes. When program gets large, and many classes, communication and interconnection gets complex Reduce this with a mediator between classes
Mediator Pattern
One objects encapsulates how the various objects of the program interact
Other objects need not know the nature or number of objects in the program they become loosely coupled.
Mediator Motivation
Dividing a program into objects generally increases re usability
But heavy interconnection between objects reduces re usability again. Lots of interconnections means an object is less likely to work without those other objects
Summary
Design Patterns:
Schema of common solutions to programming problems