0% found this document useful (0 votes)
14 views139 pages

09 - Architectural Styles and Patterns

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views139 pages

09 - Architectural Styles and Patterns

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 139

Architectural Styles and Patterns

CSCI 6221 – Advanced Software Paradigms


Fall 2023
© Ray Renner - GWU

Architectural Styles and Patterns

Reading
Taylor Richard N., Medvidovic Nenad, Dashofy Eric M. Software
Architecture: Foundations, Theory, and Practice

CSCI 6221 – Advanced Software Paradigms


2
LECTURE TITLE

Architectural Styles vs. Architectural Patterns


vs. Design Patterns
• It’s all about the scope:
§ An Architectural Style is the application design at the highest level of
abstraction;
§ An Architectural Pattern is a way to implement an Architectural Style;
§ A Design Pattern is a way to solve a localized problem.
• A single architecture can contain several Architectural Styles, and
each Architectural Style can make use of several Architectural Patterns.
• An Architecture Patterns can be a subset of an Architectural
Styles targeting a specific scope.
• Furthermore, a pattern might be able to be used both as an Architectural
Pattern or a Design Pattern, again depending on the scope we use it in, in
a specific project.

https://herbertograca.com/2017/07/28/architectural-styles-vs-architectural-patterns-vs-design-patterns/

© Ray Renner - GWU


3
LECTURE TITLE

Architectural Styles vs. Architectural Patterns


vs. Design Patterns
Examples of Architectural Styles: Examples of Architectural Patterns:

• Component-based • Three-tier
• Monolithic application • Microkernel
• Layered • Model-View-Controller
• Pipes and filters • Model-View-ViewModel
• Event-driven
• Publish-subscribe Examples of Design Patterns:
• Plug-ins
• Client-server • Builder
• Service-oriented • Object pool
• Singleton
• Lazy initialization

© Ray Renner - GWU


4
© Taylor

Architectural Styles

• An architectural style is a named collection of architectural design


decisions that
– are applicable in a given development context
– constrain architectural design decisions that are specific to a
particular system within that context
– elicit beneficial qualities in each resulting system
• A primary way of characterizing lessons from experience in
software system design
• Reflect less domain specificity than architectural patterns
• Useful in determining everything from subroutine structure to top-
level application structure
• Many styles exist and we will discuss them in detail in several
lectures

5
CSCI 6221 - Advance Software Paradigms
© Taylor

Basic Properties of Styles

• A vocabulary of design elements


§ Component and connector types; data elements
– e.g., pipes, filters, objects, servers
• A set of configuration rules
§ Topological constraints that determine allowed compositions
of elements
– e.g., a component may be connected to at most two other
components
• A semantic interpretation
§ Compositions of design elements have well-defined
meanings
• Possible analyses of systems built in a style

6
CSCI 6221 - Advance Software Paradigms
© Taylor

Benefits of Using Styles

• Design reuse
§ Well-understood solutions applied to new problems
• Code reuse
§ Shared implementations of invariant aspects of a style
• Understandability of system organization
§ A phrase such as “client-server” conveys a lot of information
• Interoperability
§ Supported by style standardization
• Style-specific analyses
§ Enabled by the constrained design space
• Visualizations
§ Style-specific depictions matching engineers’ mental models

7
CSCI 6221 - Advance Software Paradigms
© Taylor

Style Analysis Dimensions

• What is the design vocabulary?


§ Component and connector types
• What are the allowable structural patterns?
• What is the underlying computational model?
• What are the essential invariants of the style?
• What are common examples of its use?
• What are the (dis)advantages of using the style?
• What are the style’s specializations?

8
CSCI 6221 - Advance Software Paradigms
© Taylor

Architectural Patterns

• Definition
§ An architectural pattern is a set of architectural design decisions that
are applicable to a recurring design problem, and parameterized to
account for different software development contexts in which that
problem appears
• A widely used pattern in modern distributed systems is the
three-tiered system pattern
§ Science
§ Banking
§ E-commerce
§ Reservation systems

CSCI 6221 – Advanced Software Paradigms


10
© Ray Renner - GWU

Software Architecture Styles & Patterns

11
CSCI 6221 – Advanced Software Paradigms
Architectural Components

Software systems can be divided into four basic functions:

• Data storage: these are data entities documented in ERDs.

• Data access logic: the processing required to access stored


data.

• Application logic: the logic documented in the DFDs, use


cases, and functional requirements.

• Presentation logic: the display of information to the user


and the acceptance of the user’s commands.
LECTURE TITLE

ERD - Example

© Ray Renner - GWU Source: https://vertabelo.com/blog/vertabelo-tips-good-er-diagram-layout/


13
LECTURE TITLE

DFD - Example

© Ray Renner - GWU Source: http://tivexi.lukep.romet.hapolo.mohammedshrine.org/logic-diagram-shapes.html


14
Architectural Components

The three primary hardware components:

• Client computers: Input-output devices employed by


users (e.g., PCs, laptops, handheld and mobile devices,
smart phones)
• Servers: Larger multi-user computers used to store
software and data.
• Network: Connects the computers.
Comparing Architecture Options

• Most systems are built to use the existing


infrastructure in the organization, so often the
current infrastructure restricts the choice of
architecture.
• Each of the architectures discussed has its
strengths and weaknesses.
• Client-server architectures are strongly favored
on the basis of the cost of infrastructure.
• Cloud computing deserves consideration today.
Conway’s law

• Organizations, who design systems, are


constrained to produce designs which are
copies of the communication structures of
these organizations.

Melvin Conway
computer scientist, programmer, and hacker

Simply said, it means the architecture is constrained by


the communication of your teams
© Ray Renner - GWU

Client/Server Architectures

• Client/Server is simply an architectural method of providing


information to an end user; but that's where the simplicity
ends.
• Client/Server is a general description of a networked system
where a client program initiates contact with a separate server
program (usually on a different machine) for a specific
function or purpose. The client exists in the position of the
requester for the service provided by the server.

CSCI 6221 – Advanced Software Paradigms


18
Client-Server Architectures

• Client-server architectures balance the


processing between client devices and one
or more server devices.
§ Generally, clients are responsible for the
presentation logic, and
§ the server(s) are responsible for the data access
logic and data storage.
• Application logic location varies depending
on the C-S configuration chosen.
Benefits of Client-Server

• Scalable
• Can support different types of clients and
servers through middleware.
• The presentation logic, the application logic,
and the data processing logic can be
independent.
• If a server fails, only the applications
requiring that server are affected – highly
reliable.
© Ray Renner - GWU

Types of Client/Server (C/S) Architectures

• One-Tier C/S
§ Simplest form of Client/Server
§ Example: Mainframe with a dumb terminal

• Two-Tier C/S
§ In a two-tier client/server, the client communicates directly to the server
§ Example: Thick client talking directly to a database server

• Three-Tier C/S
§ Adds a third layer between the client and the server, called middleware
§ Example: Web server architecture with a web server, browser, and
database

CSCI 6221 – Advanced Software Paradigms


21
© Ray Renner - GWU

Client/Server Considerations (1/2)

• Fat Clients
§ The two-tier model initially involved a host, server and an intelligent
"fat" client where most of the processing occurs.
§ This configuration did not scale well however, to facilitate large or even
mid-size information systems (greater than 50 or so connected clients).

• Fat Servers
§ An alternative 'Thin' Client < --- > 'Fat' Server configuration, where the
user invokes procedures stored at the database server.
§ The 'Fat' Server model, is more effective in gaining performance

CSCI 6221 – Advanced Software Paradigms


22
© Ray Renner - GWU

Client/Server Considerations (2/2)

• Fat Middle
§ A three-tier architecture augments traditional client/server and two-tier
computing by introducing (one or more) middle-tier components.
§ The client system interacts with the middle-tier via a standard protocol
such as HTTP or RPC. The middle-tier interacts with the backend
server via standard database protocols such as SQL, ODBC and
JDBC.

• This middle-tier contains most of the application logic,


translating client calls into database queries and other
actions, and translating data from the database into client
data in return.

CSCI 6221 – Advanced Software Paradigms


23
© Ray Renner - GWU

N-Tier Architecture

• N-Tier applications mean using whatever mix of Computer


Hardware and/or Software Layers you need, in order to build
a modular information system.
• What does N-tier mean?
§ N-Tier means "Any Number of Tiers"
§ ~ No Limits ~
§ Levels/Layers/Tiers
§ Clients & Customers
§ Objects & Components
§ Servers & Services
• Programs partitioned into Tiers allow each layer or
component part to be developed, managed, deployed and
enhanced independently.
CSCI 6221 – Advanced Software Paradigms
24
Three-Tiered Client-Server Architecture

• Adds “specialized” servers – one for application logic; one for


data base tasks
n-Tiered Client-Server Architecture

Adds “specialized” servers – one for Web-related business logic;


one for application logic; one for data base tasks
Middleware

• Software that allows different systems to communicate and


exchange data
• Can also be used as an interface between the Internet and
private corporate systems

Image source
Adding “Tiers” in the Architecture

advantages disadvantages
§ Modular business logic § More tiers place a higher
components are shareable load on the network.
across applications § More difficult to implement
§ Separating the processing since the servers must
among multiple servers communicate effectively.
makes it possible to balance
the server loads efficiently.
Call Center Case

Imagine, you’ve a call center of 50 employees and 20 seats


(they’re going to work in a shift):
§All employees need computers
with standard set of software
§Each computer will be shared
among several Call Center agents
§Each Call Center agent shall
have his/her own workspace

§Let’s make it more complicated:


employee can choose any
computer to work

How would you organize this work?


Server-Based Architecture

• Zero-client used today in virtual desktop infrastructure (VDI)


Virtual Workstations

The virtualization software has built-in security features that allow


corporations to prohibit saving data on local devices, to encrypt all
corporate data without touching employees’ personal applications and
data, and to remotely erase the data in the event of a security breach

Case Studies: https://www.citrix.com/products/xenapp-xendesktop/case-studies.html


Mobile Application Architecture

• Rich client – involves processing on the mobile


device using its resources. Presentation logic,
business logic, and data access logic on the
client side.
• Thin Web-based client – business and data
access logic on the server side; always
connected to server.
• Rich Internet application – browser-based; uses
some technologies on client device to provide a
rich user interface (e.g., Flash).
Mobile Application Options

• Native app – written to run on specific device


with specific operating system.
• Cross-platform frameworks – develop in web-
based technologies and use framework to
deploy to multiple devices.
• Mobile Web app – browser-based; platform
independent. Most limited user experience.
Advances in Architecture Configurations

• Advances in hardware, software, and


networking have given rise to a number of new
architecture options.
§ Virtualization: Creation of a virtual device or resource.
§ Cloud computing: Computing resources obtained as a
service.
Virtualization

• Server virtualization involves partitioning a


physical server into smaller virtual servers.
• Storage virtualization involves combining
multiple network storage devices into what
appears to be single storage unit.
Virtualization

• Hardware virtualization or platform virtualization refers to the creation of a


virtual machine that acts like a real computer with an operating system.
Software executed on these virtual machines is separated from the
underlying hardware resources.
• For example, a computer that is running Windows may host a virtual machine
that looks like a computer with the Ubuntu Linux operating system.
© Ray Renner - GWU

Cloud Architectures

• What Cloud Computing Is?

• The “cloud” can be defined as the set of hardware, networks,


storage, devices, and interfaces that combine to deliver
aspects of computing as a service

• It is a pay-per-use model for enabling available, convenient,


on-demand network access to a shared pool of configurable
computing resources that can be rapidly provisioned and used
with minimal interaction

CSCI 6221 – Advanced Software Paradigms


37
© Ray Renner - GWU

NIST Definition of Cloud Computing

• Cloud computing is a model for enabling ubiquitous,


convenient, on-demand network access to a shared pool of
configurable computing resources (e.g., networks, servers,
storage, applications, and services) that can be rapidly
provisioned and released with minimal management effort or
service provider interaction.
• This cloud model is composed of
§ five essential characteristics
§ three service models
§ four deployment models.

CSCI 6221 – Advanced Software Paradigms


38
© Ray Renner - GWU

Five Essential Characteristics of Cloud


Computing (1/2)
• On-demand self-service. A consumer can unilaterally provision computing
capabilities, such as server time and network storage, as needed automatically
without requiring human interaction with each service provider.
• Broad network access. Capabilities are available over the network and accessed
through standard mechanisms that promote use by heterogeneous thin or thick
client platforms (e.g., mobile phones, tablets, laptops, and workstations).
• Resource pooling. The provider’s computing resources are pooled to serve
multiple consumers using a multi-tenant model, with different physical and virtual
resources dynamically assigned and reassigned according to consumer demand.
There is a sense of location independence in that the customer generally has no
control or knowledge over the exact location of the provided resources but may be
able to specify location at a higher level of abstraction (e.g., country, state, or
datacenter). Examples of resources include storage, processing, memory, and
network bandwidth.

CSCI 6221 – Advanced Software Paradigms


39
© Ray Renner - GWU

Five Essential Characteristics of Cloud


Computing (2/2)
• Rapid elasticity. Capabilities can be elastically provisioned and released, in some
cases automatically, to scale rapidly outward and inward commensurate with
demand. To the consumer, the capabilities available for provisioning often appear
to be unlimited and can be appropriated in any quantity at any time.
• Measured service. Cloud systems automatically control and optimize resource
use by leveraging a metering capability at some level of abstraction appropriate to
the type of service (e.g., storage, processing, bandwidth, and active user
accounts). Resource usage can be monitored, controlled, and reported, providing
transparency for both the provider and consumer of the utilized service.

CSCI 6221 – Advanced Software Paradigms


40
© Ray Renner - GWU

Cloud Computing Service Models (1/3)

• Infrastructure as a Service (IaaS)


§ The capability provided to the consumer is to provision processing,
storage, networks, and other fundamental computing resources where
the consumer is able to deploy and run arbitrary software, which can
include operating systems and applications.
§ The consumer does not manage or control the underlying cloud
infrastructure but has control over operating systems, storage, and
deployed applications; and possibly limited control of select networking
components (e.g., host firewalls).

CSCI 6221 – Advanced Software Paradigms


41
IaaS

• Infrastructure as a Service (IaaS) is the base of all


cloud services and provides on-demand physical and
virtual computing resources.
• So, if you require a Server with storage and DB, then
you’ve to look for IaaS providers.

• Example:
§ https://aws.amazon.com/ec2/
§ https://azure.microsoft.com/en-us/
© Ray Renner - GWU

Cloud Computing Service Models (2/3)

• Platform as a Service (PaaS)


§ The capability provided to the consumer is to deploy onto the cloud
infrastructure consumer-created or acquired applications created using
programming languages, libraries, services, and tools supported by the
provider.
§ The consumer does not manage or control the underlying cloud
infrastructure including network, servers, operating systems, or
storage, but has control over the deployed applications and possibly
configuration settings for the application-hosting environment.

CSCI 6221 – Advanced Software Paradigms


43
PaaS

• Platform as a Service (PaaS) is a class of Cloud


Computing services which allows its users to develop,
run, and manage applications without worrying about
the underlying infrastructure.

• PaaS can be deployed on physical servers, Stand


alone VM or IaaS.
PaaS - Heroku

Heroku is a platform as a
service (PaaS) that enables
developers to build, run, and
operate applications entirely in
the cloud.
© Ray Renner - GWU

Cloud Computing Service Models (3/3)

• Software as a Service (SaaS)


§ The capability provided to the consumer is to use the provider’s
applications running on a cloud infrastructure. The applications are
accessible from various client devices through either a thin client
interface, such as a web browser (e.g., web-based email), or a program
interface.
§ The consumer does not manage or control the underlying cloud
infrastructure including network, servers, operating systems, storage,
or even individual application capabilities, with the possible exception
of limited user-specific application configuration settings.

CSCI 6221 – Advanced Software Paradigms


46
SaaS – examples

§ Microsoft Office 365 ( www.ada.edu/mail )


§ Gmail
§ Google Docs / Sheets / Slides
§ Salesforce (CRM software)
§ Concur (travel and expense management)
IaaS, PaaS and SaaS
© Ray Renner - GWU

Cloud Deployment Models

• Private Cloud
§ The cloud infrastructure is provisioned for exclusive use by a single
organization comprising multiple consumers (e.g., business units). It
may be owned, managed, and operated by the organization, a third
party, or some combination of them, and it may exist on or off
premises.
• Community Cloud
§ The cloud infrastructure is provisioned for exclusive use by a specific
community of consumers from organizations that have shared
concerns (e.g., mission, security requirements, policy, and compliance
considerations). It may be owned, managed, and operated by one or
more of the organizations in the community, a third party, or some
combination of them, and it may exist on or off premises.

CSCI 6221 – Advanced Software Paradigms


49
© Ray Renner - GWU

Cloud Deployment Models

• Public Cloud
§ The cloud infrastructure is provisioned for open use by the general
public. It may be owned, managed, and operated by a business,
academic, or government organization, or some combination of them. It
exists on the premises of the cloud provider.
• Hybrid Cloud
§ The cloud infrastructure is a composition of two or more distinct cloud
infrastructures (private, community, or public) that remain unique
entities, but are bound together by standardized or proprietary
technology that enables data and application portability (e.g., cloud
bursting for load balancing between clouds).

CSCI 6221 – Advanced Software Paradigms


50
Hybrid Cloud

- Store sensitive information on a Private Cloud, while offering public services


based on that information from a Public Cloud.
- Meet the temporary resources needed from the Public Cloud. These
temporary resources cannot be met from a Private Cloud.

Source: wiki
© Ray Renner - GWU

Cloud Computing Advantages

• Low cost
§ Computers, disk space, infrastructure, maintenance, software cost, etc.
• Improved compatibility
§ Data formats, operating systems, etc.
• Improved performance
• Universal access to data
• Easier group collaboration
• Instant software update

CSCI 6221 – Advanced Software Paradigms


52
© Ray Renner - GWU

Cloud Computing Disadvantages

• Requires constant and high-speed internet connection


• Slower than desktop application
• Features might be limited
• Data might not be secure
• The data loss on the cloud side may lead to serious problems.

CSCI 6221 – Advanced Software Paradigms


53
Cloud – Case Study

Zynga is the developer of wildly popular Facebook


applications like FarmVille, Mafia Wars, and many
others. With over 290 million monthly active users,
Zynga’s computing demands are already significant.
When Zynga releases a new game, however, it has
no way of knowing what amount of computing
resources to dedicate to the game.

The game might be a mild success, or a smash hit that adds millions of
new users. The ability to design applications that can scale up in the
number of users quickly is one of Zynga’s competitive advantages.

Because of the uncertainty surrounding resource usage for new game


launches, Zynga uses Amazon’s cloud computing platform to launch new
offerings.
Cloud – Case Study

• Later, Zynga moves the game onto its Private Cloud, which is
structurally similar to Amazon’s cloud, but operates under
Zynga’s control in data centers on the East and West coasts.
Zynga’s own servers handle 80 percent of its games.
• Zynga recently started selling extra capacity on its Private Cloud
to other game-makers.

Source: Charles Babcock, “How Game-Maker Zynga Became a Cloud Vendor,” Information Week, May 14, 2012
Monolithic vs Microservices

• The business logic of the service can be developed in one


single place, where all functions like Authorization, Ordering,
Payment, Reporting are realized. This type of architecture is
called Monolithic.
• In Microservices, opposed to Monolithic architecture, services
work independently and contain minimum necessary
functionality that covers the given domain/function.
Monolithic vs Microservices

Source: https://medium.com/startlovingyourself/microservices-vs-monolithic-architecture-c8df91f16bb4
LECTURE TITLE

Migration to Microservices

Interesting read:

Migrating Monoliths to Microservices with Decomposition


and Incremental Changes

© Ray Renner - GWU


58
Technical Capabilities:
Architecture

Strangler Fig Pattern


Incrementally migrate a legacy system by gradually
replacing specific pieces of functionality with new
applications and services. As features from the legacy
system are replaced, the new system eventually
replaces all of the old system's features, strangling the
old system and allowing you to decommission it.
(Microsoft)

Additional read:
The seeds of the Strangler Fig are germinated on Microsoft on Strangler Fig pattern
top of other trees (dispersed by birds). These
seedlings grow their roots downward and envelop How Scholar Park moved from monolith to microservices
the host tree while also growing upward to reach Recommendations and Best Practices by Paul
into the sunlight zone above the canopy. Hammant
Technical Capabilities:
Architecture - strangler fig

https://cloud.google.com/solutions/devops/devops-tech-architecture
Service Oriented Architecture (SOA)

• SOA is a collection of services that communicate with each


other. These services are modular in nature and provide a
plug-and-play environment that serves a particular purpose.
• Microservices are a subtype of SOA where components are
decomposed into smaller functionalities and support simple,
lightweight protocols.
© Ray Renner - GWU

Service Oriented Architecture (SOA)

• An architectural style whose goal is to achieve “loose


coupling” among interacting and contracted services via
communication protocols
• A network distributed computing model
• The term service-oriented means to support service’s
dynamic description, publication, discovery, and usage.
• A method of design, deployment, and management of both
applications and the software infrastructure where:
§ Software is organized into services that are network accessible and
executable.
§ Service interfaces are based on public standards for interoperability.

CSCI 6221 – Advanced Software Paradigms


62
© Ray Renner - GWU

SOA

q Uses open standards to Multiple Service Consumers


integrate software assets Multiple Business Processes
as services
q Standardizes interactions
of services Shared
Service Architecture
q Services become building Services

blocks that form business


flows
q Services can be reused Multiple Discrete Resources
by other applications Multiple Service Providers

CSCI 6221 – Advanced Software Paradigms


63
© Ray Renner - GWU

Key Characteristics of SOA

• Quality of service, security and performance are specified.


• Software infrastructure is responsible for managing.
• Services are cataloged and discoverable.
• Data are cataloged and discoverable.
• Protocols use only industry standards.

CSCI 6221 – Advanced Software Paradigms


64
© Ray Renner - GWU

What is a Service?

• A briefer definition
§ Web services are loosely coupled, contracted components that
communicate via Internet protocols
• A closer look…
§ Loosely coupled: Web Services and programs that invoke them can
be changed independently
§ Contracted: a Web Service's behaviour, its input/output parameters
and how to bind to it are publicly available
§ Component: encapsulated code whose internal implementation is
hidden
§ XML/JSON: human-readable, text-based format that is firewall friendly
and self-describing

CSCI 6221 – Advanced Software Paradigms


65
© Ray Renner - GWU

SOA Standards

• XML (Extensible Markup Language)


§ Human readable markup language used to transfer data in web
standards
• SOAP (Simple Object Access Protocol)
§ Simple messaging framework for transferring information between
peers over web in a decentralized and distributed environment
using XML
• WSDL (Web Service Description Language)
§ An XML-based means for describing a web service and expressing
the interface to a given Web service
• UDDI (Universal Description Discovery and Integration)
§ A repository for WSDL docs

CSCI 6221 – Advanced Software Paradigms


66
© Ray Renner - GWU

Before SOA – After SOA

CSCI 6221 – Advanced Software Paradigms Source: IBM


67
© Ray Renner - GWU

SOA Enables:

• Reusability
• Legacy leverage
• Agility
• Loose coupling
• Interoperation

CSCI 6221 – Advanced Software Paradigms


68
© Ray Renner - GWU

Reusability

CSCI 6221 – Advanced Software Paradigms


69
© Ray Renner - GWU

Legacy Leverage

CSCI 6221 – Advanced Software Paradigms


70
© Ray Renner - GWU

Agility

CSCI 6221 – Advanced Software Paradigms


71
© Ray Renner - GWU

Loose Coupling

CSCI 6221 – Advanced Software Paradigms


72
© Ray Renner - GWU

Interoperation

CSCI 6221 – Advanced Software Paradigms


73
Event Driven Architecture (EDA)

• An Event-Driven Architecture (EDA) is a software architecture


pattern designed as a reaction to events.
• EDA consists of three decoupled layers : the producer,
pipeline and the consumer.
§ The producer is the one who emits an event. It is completely unaware
about what happens to the event after it is emitted.
§ The pipeline is where all the events from various producers are queued
up for processing.
§ The processed event is forwarded to the corresponding consumers.
Event Driven Architecture (EDA)

Source: https://streaml.io/blog/event-driven-architecture
© Ray Renner - GWU

Pattern Definitions

• A pattern is a recurring solution to a standard problem, in a


context.
• Christopher Alexander, a professor of architecture…
§ A Pattern Language: Towns, Buildings, Construction (1977)
§ A Timeless Way of Building (1979)
• “A pattern describes a problem which occurs over and over
again in our environment, and then describes the core of the
solution to that problem, in such a way that you can use this
solution a million times over, without ever doing it the same
way twice.”
• “Each pattern is a three-part rule which expresses a relation
between a certain context, a problem, and a solution.”

CSCI 6221 – Advanced Software Paradigms


76
© Ray Renner - GWU

Patterns in Engineering

• When experts need to solve a problem, they seldom invent a


totally new solution. More often they will recall a similar
problem they have solved previously and reuse the essential
aspects of the old solution to solve the new problem. They
tend to think in problem-solution pairs
• How do other engineers find and use patterns?
§ Mature engineering disciplines have handbooks
describing successful solutions to known problems
§ Automobile designers don't design cars from scratch
using the laws of physics
– Instead, they reuse standard designs with successful
track records, learning from experience
• Developing software from scratch is also expensive
§ Patterns support reuse of software architecture and design
CSCI 6221 – Advanced Software Paradigms
77
© Ray Renner - GWU

Pattern Oriented Software Engineering

• Frank Buschmann, Regine Meunier, Hans Rohnert, Peter


Sommerlad
§ Pattern Oriented Software Construction (1996)
• "A pattern for software architecture describes a particular
recurring design problem that arises in specific design
contexts and presents a well-proven generic scheme for its
solution. The solution scheme is specified by describing its
constituent components, their responsibilities and
relationships, and the ways in which they collaborate."

CSCI 6221 – Advanced Software Paradigms


78
© Ray Renner - GWU

Categories of Patterns

• Patterns can be grouped into three categories according to


their level of abstraction
§ Architectural Patterns or Styles
– SOA, Client-Server, etc.
§ Design Patterns
– Abstracts reoccurring class and/or object design structures
§ Idioms
– Low-level pattern specific to a programming language

CSCI 6221 – Advanced Software Paradigms


79
© Ray Renner - GWU

Pattern Characteristics

• A pattern describes a solution to a recurring problem that


arises in specific design situations.
• Patterns are not invented; they are distilled from practical
experience.
• Patterns describe a group of components (e.g., classes or
objects), how the components interact, and the
responsibilities of each component. That is, they are higher-
level abstractions than classes or objects.
• Patterns provide a vocabulary for communication among
designers. The choice of a name for a pattern is very
important.

CSCI 6221 – Advanced Software Paradigms


80
© Ray Renner - GWU

Pattern Characteristics

• Patterns help document the architectural vision of a design. If


the vision is clearly understood, it will less likely be violated
when the system is modified.
• Patterns provide a conceptual skeleton for a solution to a
design problem and, hence, encourage the construction of
software with well-defined properties
• Patterns are building blocks for the construction of more
complex designs.
• Patterns help designers manage the complexity of the
software. When a recurring pattern is identified, the
corresponding general solution can be implemented
productively to provide a reliable software system

CSCI 6221 – Advanced Software Paradigms


81
© Ray Renner - GWU

The “Gang of Four” (GoF)

• Erich Gamma, Richard Helm, Ralph Johnson


& John Vlissides (Addison-Wesley, 1995)
§ Design Patterns book catalogs 23 different patterns as solutions to
different classes of problems, in C++ & Smalltalk
§ The problems and solutions are broadly applicable, used by many
people over many years
§ GOF presents each pattern in a structured format
– Essential Elements
– Structured Descriptions

CSCI 6221 – Advanced Software Paradigms


82
© Ray Renner - GWU

Essential Elements of Design Patterns (1/2)

• Pattern Name
§ A handle to describe a design problem, its solutions and consequences
§ Allows for design at a higher level of abstraction
§ Communication mechanism for designers
• Problem
§ Describes when to apply the pattern
§ Explains the problem and its context
§ May include a list of conditions that must be met before it makes sense
to apply the pattern

CSCI 6221 – Advanced Software Paradigms


83
© Ray Renner - GWU

Essential Elements of Design Patterns (2/2)

• Solution
§ Describes the elements that make up the design, their relationships,
responsibilities and collaborations
§ It is not the design or implementation
§ A pattern is like a template
§ Provides an abstract description (UML-based) of a design problem and
how a general arrangement of elements solves it
• Consequences
§ Results and trade-offs of applying the pattern
§ Critical for evaluating design alternatives and understanding costs and
benefits of the pattern
§ The pattern's impact on the system's flexibility, extensibility or
portability may be considered

CSCI 6221 – Advanced Software Paradigms


84
© Ray Renner - GWU

Describing Design Patterns (1/4)

• Pattern Name and Classification


§ Important because it becomes part of your design vocabulary.
• Intent
§ What does the design pattern do?
§ What is its rationale and intent?
§ What particular design issue or problem does it address?
• Also Known As
§ Other well-known names for the pattern, if any.
• Motivation
§ A scenario that illustrates a design problem and how the class and
object structures in the pattern solve the problem

CSCI 6221 – Advanced Software Paradigms


85
© Ray Renner - GWU

Describing Design Patterns (2/4)

• Applicability
§ When should the pattern be applied?
§ How can you recognize these situations?
• Structure
§ A graphical representation of the classes in the pattern using a notation
such as Object Modeling Technique (OMT) or UML to illustrate
sequences of requests and collaborations.
• Participants
§ The classes and/or objects participating in the design pattern and their
responsibilities.
• Collaborations
§ How the participants collaborate to carry out their responsibilities.

CSCI 6221 – Advanced Software Paradigms


86
© Ray Renner - GWU

Describing Design Patterns (3/4)

• Consequences
§ How does the pattern support its objectives?
§ What are the trade-offs and results of using the pattern?
§ What aspect of system structure does it let you vary independently?
• Implementation
§ What pitfalls, hints, or techniques should you be aware of when
implementing the pattern?
§ Are there language-specific issues?
• Sample Code
§ Code fragments that illustrate how you might implement the pattern in a
particular object-oriented language.

CSCI 6221 – Advanced Software Paradigms


87
© Ray Renner - GWU

Describing Design Patterns (4/4)

• Known Uses
§ Examples of the pattern found in real systems.
• Related Patterns
§ What design patterns are closely related to this one?
§ What are the important differences?
§ With which other patterns should this one be used?

CSCI 6221 – Advanced Software Paradigms


88
© Ray Renner - GWU

Classification of Design Patterns


by purpose and scope

• Creational patterns

§ Abstract the instantiation process


§ Make a system independent to its realization
§ Class Creational use inheritance to vary the instantiated classes
§ Object Creational delegate instantiation to another object

CSCI 6221 – Advanced Software Paradigms


89
© Ray Renner - GWU

Classification of Design Patterns

• Structural patterns

§ Class Structural patterns concern the aggregation of classes to form


largest structures

§ Object Structural pattern concern the aggregation of objects to form


largest structures

CSCI 6221 – Advanced Software Paradigms


90
© Ray Renner - GWU

Classification of Design Patterns

• Behavioral patterns

§ Concern with algorithms and assignment of responsibilities between


objects
§ Describe the patterns of communication between classes or objects
§ Behavioral class pattern use inheritance to distribute behavior
between classes
§ Behavioral object pattern use object composition to distribute
behavior between classes

CSCI 6221 – Advanced Software Paradigms


91
© Ray Renner - GWU

Design Patterns (Gamma)

Purpose
Creational Structural Behavioral
Factory Method Adapter Interpreter
Class Template Method

Abstract Factory Adapter Chain of


Responsibility

Builder Bridge Command

Prototype Composite Iterator


Scope Singleton Decorator Mediator
Object Façade Memento

Flyweight Observer

Proxy State

Strategy

Visitor

CSCI 6221 – Advanced Software Paradigms


92
© Ray Renner - GWU

Creational Patterns

• Abstract Factory:
§ Factory for building related objects
• Builder:
§ Factory for building complex objects incrementally
• Factory Method:
§ Method in a derived class creates associates
• Prototype:
§ Factory for cloning new instances from a prototype
• Singleton:
§ Factory for a singular (sole) instance

CSCI 6221 – Advanced Software Paradigms


93
© Ray Renner - GWU

Structural Patterns

• Adapter:
§ Translator adapts a server interface for a client
• Bridge:
§ Abstraction for binding one of many implementations
• Composite:
§ Structure for building recursive aggregations
• Decorator:
§ Decorator extends an object transparently
• Facade:
§ Simplifies the interface for a subsystem
• Flyweight:
§ Many fine-grained objects shared efficiently.
• Proxy:
§ One object approximates another

CSCI 6221 – Advanced Software Paradigms


94
© Ray Renner - GWU

Behavioral Patterns

• Chain of Responsibility:
§ Request delegated to the responsible service provider
• Command:
§ Request or Action is first-class object, hence re-storable
• Iterator:
§ Aggregate and access elements sequentially
• Interpreter:
§ Language interpreter for a small grammar
• Mediator:
§ Coordinates interactions between its associates
• Memento:
§ Snapshot captures and restores object states privately

CSCI 6221 – Advanced Software Paradigms


95
© Ray Renner - GWU

Behavioral Patterns (cont.)

• Observer:
§ Dependents update automatically when subject changes
• State:
§ Object whose behavior depends on its state
• Strategy:
§ Abstraction for selecting one of many algorithms
• Template Method:
§ Algorithm with some steps supplied by a derived class
• Visitor:
§ Operations applied to elements of a heterogeneous object structure

CSCI 6221 – Advanced Software Paradigms


96
© Ray Renner - GWU

How To Use a Design Pattern?

• Read the pattern once through for an overview.


§ Pay special attention to the Applicability and Consequences sections
§ Ensure the pattern is right for your problem
• Go back and study the Structure, Participants and Collaborations
sections
• Look at the sample code.
• Choose names for pattern participants that are meaningful in the
application context.
• Define the classes.
• Define application-specific names for operations in the pattern.
• Implement the operations to carry out the responsibilities and
collaborations in the pattern.

CSCI 6221 – Advanced Software Paradigms


97
© Ray Renner - GWU

Design Pattern Selection

• Consider how design patterns solve design problems.


§ Find appropriate objects
§ Determine object granularity
§ Specify object interfaces
• Scan Intent sections.
• Study how patterns interrelate.
• Study patterns of like purpose.
§ Study similarities and differences
• Examine a cause of redesign.
§ Consider what might force a change to your design
• Consider what should be variable in your design.
§ Consider what you want to be able to change without redesign -
encapsulate the concept that varies
CSCI 6221 – Advanced Software Paradigms
98
© Ray Renner - GWU

Singleton Pattern

• Motivation
§ we need to have exactly only one instance for a class (ex. Printer
spooler)
§ Make the class itself responsible for keeping track of its sole instance
§ The class provide a way to access the instance

• Applicability
§ There must be only one instance of a class accessible from a well-
known point

CSCI 6221 - Advanced Software Paradigms


99
© Ray Renner - GWU

Singleton Pattern

• Structure

Singleton
Return
Static Instance()
uniqueInstance
SingletonOperation()
GetSingletonData()

Static uniqueInstance
SingletonData

CSCI 6221 - Advanced Software Paradigms


100
© Ray Renner - GWU

Singleton Pattern

• Participants
§ Singleton class
• Collaborations
§ Access only through Singleton’s instance operation
• Consequences
§ Controlled access to sole instance
§ Permits refinement of operation and representation
§ More flexible than class operations

CSCI 6221 - Advanced Software Paradigms


101
© Ray Renner - GWU

Example of Singleton use

• We had to have only one instance for class Director. We


simply solve our problem using Singleton Pattern

Director

Static Instance()
Given(n_ticket:int):void
Error():void

Static UniqueInstance

CSCI 6221 - Advanced Software Paradigms


102
© Ray Renner - GWU

What Makes it a Pattern?

• A Pattern must:
§ Solve a problem and be useful
§ Have a context and can describe where the solution can be used
§ Recur in relevant situations
§ Provide sufficient understanding to tailor the solution
§ Have a name and be referenced consistently

CSCI 6221 – Advanced Software Paradigms


103
© Ray Renner - GWU

When to Use Patterns

• Solutions to problems that recur with variations


§ No need for reuse if problem only arises in one context
• Solutions that require several steps:
§ Not all problems need all steps
§ Patterns can be overkill if solution is a simple linear set of instructions
• Solutions where the solver is more interested in the existence
of the solution than its complete derivation
§ Patterns leave out too much to be useful to someone who really wants
to understand
§ They can be a temporary bridge

CSCI 6221 – Advanced Software Paradigms


104
© Ray Renner - GWU

Benefits of Design Patterns

• Design patterns enable medium-scale reuse of software


architectures and also help document systems
• Patterns explicitly capture expert knowledge and design
tradeoffs and make it more widely available
• Patterns help improve developer communication
• Pattern names form a common vocabulary

CSCI 6221 – Advanced Software Paradigms


105
© Ray Renner - GWU

Drawbacks to Design Patterns

• Patterns do not lead to direct code reuse


• Patterns are deceptively simple
• Teams may suffer from pattern overload
• Patterns are validated by experience and discussion rather
than by automated testing
• Integrating patterns into a software development process is a
human-intensive activity.

CSCI 6221 – Advanced Software Paradigms


106
© Ray Renner - GWU

Suggestions for Effective Use

• Do not recast everything as a pattern


§ Instead, develop strategic domain patterns and reuse existing tactical
patterns
• Institutionalize rewards for developing patterns
• Directly involve pattern authors with application developers
and domain experts
• Clearly document when patterns apply and do not apply
• Manage expectations carefully.

CSCI 6221 – Advanced Software Paradigms


107
© Ray Renner - GWU

Model-View-Controller Design Pattern

• Name (essence of the pattern)


§ Model View Controller (MVC)

• Context (where does this problem occur)


§ MVC is an architectural pattern that is used when developing
interactive application such as a shopping cart on the Internet.

• Problem (definition of the reoccurring difficulty)


§ User interfaces change often, especially on the internet where look-
and-feel is a competitive issue. Also, the same information is presented
in different ways. The core business logic and data is stable.

CSCI 6221 - Advanced Software Paradigms


108
© Ray Renner - GWU

MVC continued

• Solution (how do you solve the problem)


§ Use the software engineering principle of “separation of concerns” to
divide the application into three areas:
§ Model encapsulates the core data and functionality
§ View encapsulates the presentation of the data there can be many
views of the common data
§ Controller accepts input from the user and makes request from the
model for the data to produce a new view.

CSCI 6221 - Advanced Software Paradigms


109
© Ray Renner - GWU

How did it come about?

• Presented by Trygve Reenskaug in 1979


• First used in the Smalltalk-80 framework
§ Used in making Apple interfaces (Lisa and Macintosh)

CSCI 6221 – Advanced Software Paradigms


110
© Ray Renner - GWU

MVC Structure

CSCI 6221 – Advanced Software Paradigms


111
© Ray Renner - GWU

Model Role

• The Model maintains the application state and contains the


data, which includes:
§ Persistent information stored in databases
§ Current information related to active sessions
§ Has methods to access and update it’s data and state.
§ Often, it implements an interface which defines the allowed model
interactions. Implementing an interface enables models to be pulled out
and replaced without code changes.
• Responsibilities include:
§ Applying rules / transactions to modify state
§ Notifies Views of change
§ Taking instructions from the Controller
§ Responds to state queries

CSCI 6221 – Advanced Software Paradigms


112
© Ray Renner - GWU

View Role

• The View presents a user interface, including information and


transactional controls
§ There can be multiple views displaying the model at any one time.
– For example, a companies finances over time could be represented as a
table and a graph.
– These are just two different views of the same data.
§ When the Model is updated, all Views are informed and given a chance
to update themselves.
• Responsibilities include:
§ Present required information to user
§ Request data from Model as needed (to create displays for the user)
§ Sends User Gestures to Controller
§ Allows the Controller to select the appropriate View

CSCI 6221 – Advanced Software Paradigms


113
© Ray Renner - GWU

Controller Role

• The Controller handles user actions


§ Users interact with the controller.
§ It interprets mouse movement, clicks, keystrokes, etc
§ Communicates those activities to the model – eg: delete row, insert row
§ It’s interaction with the model indirectly causes the View(s) to update
• Responsibilities include:
§ Maps user actions to Model updates and/or View changes
§ Validate user requests (correctness, completeness)
§ Invoke Model components to handle requested transactions
§ Set the appropriate View perspective

CSCI 6221 – Advanced Software Paradigms


114
© Ray Renner - GWU

MVC Component Responsibilities

q View: Present the user


interface

q Controller: Handle
user actions

q Model: Maintain the


application state

CSCI 6221 – Advanced Software Paradigms


115
© Ray Renner - GWU

MVC Implementation with Observer Pattern

q Individual Views
implement the Observer
interface and register with
the model.
q The model tracks the list
of all observers that
subscribe to changes.
q When a model changes,
the model iterates through
all registered observers
and notifies them of the
change.

CSCI 6221 – Advanced Software Paradigms


116
© Ray Renner - GWU

MVC Example

a = 50% b
b = 30%
Views c = 20% a c
a b c

Controller
See
Interact
a b c
Model 503020

CSCI 6221 – Advanced Software Paradigms


117
© 2005 Roger L. Costello, Timothy D. Kehoe.

REST – Architectural Pattern

" REST " was coined by Roy Fielding


in his Ph.D. dissertation [1] to describe a
design pattern for implementing
networked systems.

[1] http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
CSCI 6221 – Advanced Software Paradigms
118
© 2005 Roger L. Costello, Timothy D. Kehoe.

Why is it called
"Representational State Transfer? "

http://www.boeing.com/aircraft/747
Client Resource
Fuel requirements
Maintenance schedule
...

Boeing747.html

The Client references a Web resource using a URL.


A representation of the resource is returned (in this case as an HTML document).
The representation (e.g., Boeing747.html) places the client in a new state.
When the client selects a hyperlink in Boeing747.html, it accesses another resource.
The new representation places the client application into yet another state.
Thus, the client application transfers state with each resource representation.
CSCI 6221 – Advanced Software Paradigms
119
© 2005 Roger L. Costello, Timothy D. Kehoe.

Representational State Transfer

"Representational State Transfer is intended to evoke an


image of how a well-designed Web application behaves: a
network of web pages (a virtual state-machine),
where the user progresses through an application
by selecting links (state transitions), resulting in the
next page (representing the next state of the application)
being transferred to the user and rendered for their use."

- Roy Fielding

CSCI 6221 – Advanced Software Paradigms


120
© 2005 Roger L. Costello, Timothy D. Kehoe.

Motivation for REST

The motivation for developing REST was to create


a design pattern for how the Web should work,
such that it could serve as the guiding framework
for the Web standards and designing Web
services.

CSCI 6221 – Advanced Software Paradigms


121
© 2005 Roger L. Costello, Timothy D. Kehoe.

REST - Not a Standard

• REST is not a standard


§ You will not see the W3C putting out a REST specification.
§ You will not see IBM or Microsoft or Sun selling a REST
developer's toolkit.
• REST is just a design pattern
§ You can't bottle up a pattern.
§ You can only understand it and design your Web services to it.
• REST does prescribe the use of standards:
§ HTTP
§ URL
§ XML/HTML/GIF/JPEG/etc. (Resource Representations)
§ text/xml, text/html, image/gif, image/jpeg, etc. (Resource
Types, MIME Types)

CSCI 6221 – Advanced Software Paradigms


122
© 2005 Roger L. Costello, Timothy D. Kehoe.

Learn by Example

• The REST design pattern is best explained with an example.


• I will present an example of a company deploying three Web
services using the REST design pattern.

CSCI 6221 – Advanced Software Paradigms


123
© 2005 Roger L. Costello, Timothy D. Kehoe.

Parts Depot Web Services

• Parts Depot, Inc has deployed some web services to enable


its customers to:
§ get a list of parts
§ get detailed information about a particular part
§ submit a Purchase Order (PO)

CSCI 6221 – Advanced Software Paradigms


124
© 2005 Roger L. Costello, Timothy D. Kehoe.

The REST way of Designing the Web Services

HTTP GET request URL 1 Parts


Response
HTTP response List
(HTML/XML doc)

Web Server
HTTP GET request URL 2 Part
Response
HTTP response Data
(HTML/XML doc)

PO URL 3
HTTP POST
(HTML/XML) PO
URL to submitted PO HTTP response

CSCI 6221 – Advanced Software Paradigms


125
© 2005 Roger L. Costello, Timothy D. Kehoe.

Web Service for Clients to Retrieve a List of


Parts
• Service: Get a list of parts
• The web service makes available a URL to a parts list
resource. A client uses this URL to get the parts list:
§ http://www.parts-depot.com/parts
• Note that how the web service generates the parts list is
completely transparent to the client. This is loose coupling.

CSCI 6221 – Advanced Software Paradigms


126
© 2005 Roger L. Costello, Timothy D. Kehoe.

REST Fundamentals

• Create a resource for every service.


• Identify each resource using a URL.

CSCI 6221 – Advanced Software Paradigms


127
© 2005 Roger L. Costello, Timothy D. Kehoe.

Data Returned - Parts List

<?xml version="1.0"?>
<Parts>
<Part id="00345" href="http://www.parts-depot.com/parts/00345"/>
<Part id="00346" href="http://www.parts-depot.com/parts/00346"/>
<Part id="00347" href="http://www.parts-depot.com/parts/00347"/>
<Part id="00348" href="http://www.parts-depot.com/parts/00348"/>
</Parts>

Note that the parts list has links to get detailed info about each part.
This is a key feature of the REST design pattern. The client transfers
from one state to the next by examining and choosing from among
the alternative URLs in the response document.

CSCI 6221 – Advanced Software Paradigms


128
© 2005 Roger L. Costello, Timothy D. Kehoe.

REST Fundamentals

• The data that a Web service returns should link to other data.
Thus, design your data as a network of information.
• Contrast with OO design, which says to encapsulate
information.

CSCI 6221 – Advanced Software Paradigms


129
© 2005 Roger L. Costello, Timothy D. Kehoe.

Web Service for Clients to Retrieve a Particular


Part
• Service: Get detailed information about a particular part
• The web service makes available a URL to each part
resource. For example, here's how a client requests a
specific part:
§ http://www.parts-depot.com/parts/00345

CSCI 6221 – Advanced Software Paradigms


130
© 2005 Roger L. Costello, Timothy D. Kehoe.

Data Returned - Part 00345

<?xml version="1.0"?>
<Part>
<Part-ID>00345</Part-ID>
<Name>Widget-A</Name>
<Description>This part is used within the frap assembly</Description>
<Specification href="http://www.parts-depot.com/parts/00345/specification"/>
<UnitCost currency="USD">0.10</UnitCost>
<Quantity>10</Quantity>
</Part>

Again observe how this data is linked to still more data - the
specification for this part may be found by traversing the hyperlink.
Each response document allows the client to drill down to get
more detailed information.

CSCI 6221 – Advanced Software Paradigms


131
© 2005 John Cowan under GPL

REST Architectural Styles

• Client-server
• Stateless
• Cached
• Uniform interface
• Layered system
• (Code on demand)

CSCI 6221 – Advanced Software Paradigms


132
© 2005 Roger L. Costello, Timothy D. Kehoe.

The REST Design Pattern

• Create a resource for every service.


• Uniquely identify each resource with a logical URL.
• Design your information to link to other information.
That is, the information that a resource returns to a client
should link to other information in a network of related
information.

CSCI 6221 – Advanced Software Paradigms


133
© 2005 Roger L. Costello, Timothy D. Kehoe.

The REST Design Pattern (cont.)

• All interactions between a client and a web service are


done with simple operations. Most web interactions
are done using HTTP and just four operations:
§ retrieve information (HTTP GET)
§ create information (HTTP PUT)
§ update information (HTTP POST)
§ delete information (HTTP DELETE)

CSCI 6221 – Advanced Software Paradigms


134
Architecture Pattern

Request HTTP GET


(XML doc) URL 1 doGet()

Response HTTP Response

Web/Proxy Server
(XML doc)

doPost(id)
Request
(XML doc)
HTTP POST
URL 1 REST Engine
(locate resource
Response HTTP Response and generate
(JSON doc) response) doDelete()

PO HTTP DELETE
(XML doc) URL 1

Response HTTP Response


(TEXT doc)

135
© Ray Renner - GWU

Publish/Subscribe Pattern

CSCI 6221 – Advanced Software Paradigms


http://www.enterpriseintegrationpatterns.com/ramblings/82_googlepubsub.html 138
© Ray Renner - GWU

Data Source Adapter

a variation on the Adapter pattern

http://www.servicedesignpatterns.com/WebServiceImplementationStyles/DatasourceAdapter
CSCI 6221 – Advanced Software Paradigms
139
© Ray Renner - GWU

Idioms

• Definition: "An idiom is a low-level pattern specific to a


programming language. An idiom describes how to implement
particular aspects of components or the relationships between
them using the features of the given language." [Buschmann]
• An idiom is a low-level abstraction. It is usually a language-
specific pattern that deals with some aspects of both design
and implementation.

CSCI 6221 – Advanced Software Paradigms


141
© Ray Renner - GWU

Idiom Example: Java Iterator

ArrayList<String> alist = new ArrayList<String>();


// . . . Add Strings to alist

for (Iterator<String> it = alist.iterator(); it.hasNext(); )


{
String s = it.next(); // No downcasting required.
System.out.println(s);
}

CSCI 6221 – Advanced Software Paradigms


142
LECTURE TITLE

License

Attribution-ShareAlike 3.0 Unported


You are free:
to Share — to copy, distribute and transmit the work
to Remix — to adapt the work

Under the following conditions:


Attribution. You must attribute the work in the manner specified by the author or licensor
(but not in any way that suggests that they endorse you or your use of the work).
Share Alike. If you alter, transform, or build upon this work, you may distribute the
resulting work only under the same, similar or a compatible license.
For any reuse or distribution, you must make clear to others the license terms of this work. The
best way to do this is with a link to this web page.
Any of the above conditions can be waived if you get permission from the copyright holder.
Nothing in this license impairs or restricts the author's moral rights.

http://creativecommons.org/licenses/by-sa/3.0/
© Ray Renner - GWU
143

You might also like