Shared Flashcard Set

Details

CS Design Patterns
Computer Science Design Patterns
46
Computer Science
Professional
08/11/2011

Additional Computer Science Flashcards

 


 

Cards

Term
Abstract Factory
Definition

Provide an interface for creating families of related or dependent objects without specifying their concrete classes

 

 

 

Create a specific factory...then use the generic upper level interface action methods.  At that level we don't care exactly what type just that it has the interface.

 

 

Term
Builder
Definition

Separate the construction of a complex object from its representation allowing the same construction process to create various representations

 

Can use an abstract methods to outline the construction process, then force the sub classes to implement the details.

Term
Factory Method
Definition

Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.  

Basically a Factory creates classes.  Here you let subclasses decide the exact type to create.

 

Term
Lazy Initialization
Definition
Tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.
Term
Multiton
Definition

Ensure a class has only named instances, and provide global point of access to them.  Use a Map to make sure that you have only one instance per key name.

 

Term
Object Pool
Definition
Avoid expensive acquisition and release of resources by recycling objects that are no longer in use. Can be considered a generalisation of connection pool and thread pool patterns.
Term
Prototype
Definition

Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Example implements cloneable .clone() in Java

 

 

 

Term
Resource Acquisition is Initialization (RAII)
Definition
Ensure that resources are properly released by tying them to the lifespan of suitable objects.  Not used in JAVA because objects must be accessed through references.  Not directly onthe  stack.
Term
Singelton
Definition
Ensure a class has only one instance, and provide a global point of access to it. No matter who accesses it you get the same class
public class Singleton {
private static final Singleton instance = new Singleton();

// Private constructor prevents instantiation from other classes
private Singleton() {
}

public static Singleton getInstance() {
return instance;
}

}
Term
Adapter or Wrapper
Definition
Convert the interface of a class into another interface clients expect. An adapter lets classes work together that could not otherwise because of incompatible interfaces.
Term
Bridge
Definition

Decouple an abstraction from its implementation allowing the two to vary independently.  Use whenthe class and what it does varies often.

 

 

Term
Composite
Definition
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.  Example is a File System Tree.  Leaves can be other Leaves or files.  So this sturcture can handle this.
Term
Decorator
Definition
Attach additional responsibilities to an object dynamically keeping the same interface. Decorators provide a flexible alternative to subclassing for extending functionality.
Term
Facade
Definition
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Term
Front Controller
Definition
Provide a unified interface to a set of interfaces in a subsystem. Front Controller defines a higher-level interface that makes the subsystem easier to use.  Dispatcher Servlet in Spring it handles all requests then forwards them to wherever appropriate.
Term
Flyweight
Definition
Use sharing to support large numbers of fine-grained objects efficiently.  So if taking Coffee Orders, you don't have to store every single table number and coffee flavor order.  Just stor the table number and reference one of the coffee flavors.  If 2 tables have the same coffee flavor order...the both reference the same object.
Term
Proxy
Definition
Provide a surrogate or placeholder for another object to control access to it.  Access Control can be for security or memory or  other reasons.
Term
Blackboard
Definition
Generalized observer, which allows multiple readers and writers. Communicates information system-wide.
Term
Chain of Responsibility
Definition
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
Term
Command
Definition

Encapsulate a request as an object.  The Command pattern then forwards that request to the spefic object to be executed.

 

Term
Interpreter
Definition
Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.  It will read a sentance you give it, and perform actions.
Term
Iterator
Definition
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.  ArrayList is an example
Term
Mediator
Definition
Define an object that encapsulates how a set of objects interact. Mediator promotesloose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.  All communication goes through the mediator, instead of from object to object.
Term
Memento
Definition
Without violating encapsulation, capture and externalize an object's internal state allowing the object to be restored to this state later.  Great for undo mechanism
Term
Null Object
Definition
Avoid null references by providing a default object.
Term
Observer or Publish/Subscribe
Definition
Define a one-to-many dependency between objects where a state change in one object results with all its dependents being notified and updated automatically.  Example Java Observabel interface.  When there is a change notify all observers.
Term
Servant
Definition
Define common functionality for a group of classes.  Simlar to Command.
Term
Specification
Definition
Recombinable business logic in a Boolean fashion
Term
State
Definition
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.  Example coin machine...if it has change it will give change...if it runs out the state changes and it will require exact change.
Term
Strategy
Definition
Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.  The pattern allows you to choose from a number of strategies at runtime.
Term
Template Method
Definition
Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template method lets subclasses redefine certain steps of an algorithm without changing the algorithm's structure.  When behavior vaires leave it up to subclasses to implement.
Term
Visitor
Definition
Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.  Keeps your objects simple, and keeps the tasks you run on them seperate.
Term
Active Object
Definition
Decouples method execution from method invocation that reside in their own thread of control. The goal is to introduce concurrency, by using asynchronous method invocation and a scheduler for handling requests.
Term
Balking
Definition
Only execute an action on an object when the object is in a particular state.
Term
Binding Properties
Definition
Combining multiple observers to force properties in different objects to be synchronized or coordinated in some way
Term
Messaging Design Pattern (MDP)
Definition
Allows the interchange of information (i.e. messages) between components and applications.
Term
Double-Checked Locking
Definition

Reduce the overhead of acquiring a lock by first testing the locking criterion (the 'lock hint') in an unsafe manner; only if that succeeds does the actual lock proceed.

Can be unsafe when implemented in some language/hardware combinations. It can therefore sometimes be considered an anti-pattern.

Term
Event-based Asynchronous
Definition
Addresses problems with the asynchronous pattern that occur in multithreaded programs.
Term
Guarded Suspension
Definition
Manages operations that require both a lock to be acquired and a precondition to be satisfied before the operation can be executed.
Term
Lock
Definition
One thread puts a "lock" on a resource, preventing other threads from accessing or modifying it.
Term
Monitor Object
Definition
An object whose methods are subject to mutual exclusion, thus preventing multiple objects from erroneously trying to use it at the same time.
Term
Reactor
Definition
A reactor object provides an asynchronous interface to resources that must be handled synchronously.
Term
Read-Write Lock
Definition
Allows concurrent read access to an object, but requires exclusive access for write operations.
Term
Scheduler
Definition
Explicitly control when threads may execute single-threaded code.
Term
Thread Pool
Definition
A number of threads are created to perform a number of tasks, which are usually organized in a queue. Typically, there are many more tasks than threads. Can be considered a special case of the object pool pattern.
Term
Thread-Specific Storage
Definition
Static or "global" memory local to a thread.
Supporting users have an ad free experience!