Introduction to Design Patterns Flashcards
Software design pattern
A general reusable solution to a commonly occurring problem within a given context in software design
Algorithm strategy patterns
High-level strategies describing how to exploit application characteristics on a computing platform
Computational design pattern
Key computation identification
Reader
Used to read from the keyboard or from disk files or other media, or to obtain information over the net
StringTokenizer
To separate a larger string into different token
BufferedReader
- Read a lot of characters at once
2. Provide any other reader with the ability to buffer its input
Java Input
- Java uses a set of classes called readers to read text from files
- Store in ASCII, but later replaced by Unicode form
Strategy Pattern
- Layout objects in the Java AWT implements a strategy pattern
- To factor out variables that might be a set of problems and build an interface for that. Then write solutions in terms of the interface
Decorator Pattern
- A set of objects defined by an interface.
- Java I/O classes are mostly decorators
- A bufferedReader is just a decorator for a reader
Composite Pattern
- To have a container that implements an interface and it contains objects that also implement the same interface
- Java AWT Panel is built with the composite pattern
Panel
- A component, but it also contains component
2. A container that contains things that implement the same interfaces
Iterator Pattern
An iterator is used to traverse a container and access the container’s element
Model-View-Controller
- A software architectural pattern for implementing user interfaces on computers
- To achieve a clean separation between three components of most any web application
Model (Component)
The application’s behavior in terms of the problem domain, independent of the user interface
View (Component)
Any output representation of information, such as a chart or a diagram. Multiple view of the same information are possible, such as a bar chart for management and a tabular view for accountants
Controller (Component)
Accepts input and converts it to commands for the model or view
Model (Interactions)
Stores data that is retrieved according to commands from the controller and displayed in the view
View (Interactions)
Generates new output to the user based on changes in the model
Controller (Interactions)
Send commands to the model to update the model’s state. It can also send commands to its associated view to change the view’s presentation of the model
Simultaneous development
Because MVC decouples the various components of an application, developers are able to work in parallel on different components without impacting and/or blocking one another
Code reuse
By creating components that are independent, developers are able to reuse components quickly and easily in other applications
MVC (Advantage)
- Separation of concerns in the codebase
- Developer specialization and focus
- Parallel development by separate teams
MVC (Disadvantage)
Code navigability
Multi-artifact consistency
Pronounced learning curve
Separation of concerns
- One layer doesn’t care how another layer is implemented
2. Discourages “cut-&-paste” repetition of code, streamlining upgrade & maintenance tasks
Developer specialization and focus
Ex: UI developers can focus exclusively on UI, without getting bogged down in business logic rules or code
The application’s model includes
- Application state
- Application rules
- Persisten data
Application state
- People
2. Widgets needed by application users (Shopping carts, transcripts, contact information)
Persistent data
Long-term storage of data - beyond the scope and time-frame of the user’s session in the application
View (Detail)
- Elements of the view
- View technologies
- Templating
- Styling
- The decorator pattern
Elements of the view
- Core data
- Business logic widgets
- Navigation widgets
- Skin
Core data
The subject of a page’s business
Business logic widgets
Ex: Buttons to perform edit or save
Navigation widgets
Ex: Navigation bar, logout button
Skin
Standard look of the site: logos, colors, footer, copyright, etc
View technologies
Used to render the user interface (UI) in a way that properly and dynamically links it to the application’s business-logic and data layer
Java server pages (JSPs)
A widely-utilized technology for constructing dynamic web pages. JSPs contain a mix of static markup and JSP-specific coding that references or executes Java.
In brief:
- JSP Tags call compiled Java classes in the course of generating dynamic pages
- JSP Directives are instructions processed when the JSP is compiled. Directives set page-level instructions, insert data from external files, and specify custom tag libraries
- Java code - in sections called “scriptlets” - can be included in JSP pages directly, but this practice is strongly discouraged in favor of using JSP Tags
JSP tags
call compiled Java classes in the course of generating dynamic pages
JSP directives
Instructions processed when the JSP in compiled. Directives set page-level instructions, insert data from external files, and specify custom tag libraries
Java code
in sections called “scriptlets” - can be included in JSP pages directly, but this practice is strongly discouraged in favor of using JSP tags
XML pipelining
Another technique for rendering the User Interface. Apache’s Cocoon and Orbeon’s OXF are technologies that use this technique.
Templating
Render a consistent header, footer, and navigation UI around the core business content standardizes a site’s graphics presence, which tends very strongly toward making users’ experience smoother and less prone to error
Controller (Detail)
- Responsibilities of the controller
2. Controller technologies
Responsibilities of the controller
- Parse a user request
- Validate the user request
- Determine what the user is trying to do
- Obtain data from the Model to include in response to user
- Select the next view the client should see
Controller technologies
- Structs
- Java Server Faces
- WebWork
- Spring
What deployment descriptors do
Deployment descriptor = configuration file
Used to configure an application as it starts up in its container. Configuring includes wiring its components together
Observer pattern
A software design pattern in which an object, called the subject, maintains a list of its dependents, called observers and notifies them automatically of any state changes, usually by calling one of their methods
CSS
used to specify colors, backgrounds, fonts and font-size, block-element alignment, borders, margins, list-item markers, etc.
Decorator Pattern (MVC)
Wrapping some core object in something that gives it additional functionality.
- Core business information in a
- Template (header + footer + navigation), which includes (in the common HTML header) reference to a CSS stylesheet (where background, colors, fonts, etc)
Code navigability
The framework navigation can be complex because it introduces new layers of abstraction and requires users to adapt to the decomposition criteria of MVC.
Multi-artifact consistency
Decomposing a feature into three artifacts causes scattering. Thus, requiring developer(s) to maintain the consistency of multiple representations at once.
Pronounced learning curve
Knowledge on multiple technologies becomes the norm. Developers using MVC need to be skilled in multiple technologies.
What is the essential purpose of the Model-view-controller pattern?
Separate information from how it is presented
Which of these are typical relationships among the Model, View, and Controller?
- Controller tells model to update its data
2. Model tells view that data has changed
Think about the base 4 calculator. Which MVC components(s) does the Base4CalcState (the “actual” calculator) represent?
Model and View
A swing component can be part of the View, or part of the Controller, but not both
true