09 - Architectural Styles and Patterns
09 - Architectural Styles and Patterns
Reading
Taylor Richard N., Medvidovic Nenad, Dashofy Eric M. Software
Architecture: Foundations, Theory, and Practice
https://herbertograca.com/2017/07/28/architectural-styles-vs-architectural-patterns-vs-design-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
Architectural Styles
5
CSCI 6221 - Advance Software Paradigms
© Taylor
6
CSCI 6221 - Advance Software Paradigms
© Taylor
• 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
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
11
CSCI 6221 – Advanced Software Paradigms
Architectural Components
ERD - Example
DFD - Example
Melvin Conway
computer scientist, programmer, and hacker
Client/Server Architectures
• 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
• 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
• 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
• 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.
N-Tier Architecture
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
Cloud Architectures
• Example:
§ https://aws.amazon.com/ec2/
§ https://azure.microsoft.com/en-us/
© Ray Renner - GWU
Heroku is a platform as a
service (PaaS) that enables
developers to build, run, and
operate applications entirely in
the cloud.
© Ray Renner - GWU
• 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.
• 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).
Source: wiki
© Ray Renner - GWU
• 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
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.
• 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
Source: https://medium.com/startlovingyourself/microservices-vs-monolithic-architecture-c8df91f16bb4
LECTURE TITLE
Migration to Microservices
Interesting read:
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
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
SOA Standards
SOA Enables:
• Reusability
• Legacy leverage
• Agility
• Loose coupling
• Interoperation
Reusability
Legacy Leverage
Agility
Loose Coupling
Interoperation
Source: https://streaml.io/blog/event-driven-architecture
© Ray Renner - GWU
Pattern Definitions
Patterns in Engineering
Categories of Patterns
Pattern Characteristics
Pattern Characteristics
• 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
• 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
• 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.
• 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.
• 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?
• Creational patterns
• Structural patterns
• Behavioral patterns
Purpose
Creational Structural Behavioral
Factory Method Adapter Interpreter
Class Template Method
Flyweight Observer
Proxy State
Strategy
Visitor
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
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
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
• 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
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
Singleton Pattern
• Structure
Singleton
Return
Static Instance()
uniqueInstance
SingletonOperation()
GetSingletonData()
Static uniqueInstance
SingletonData
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
Director
Static Instance()
Given(n_ticket:int):void
Error():void
Static UniqueInstance
• 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
MVC continued
MVC Structure
Model Role
View Role
Controller Role
q Controller: Handle
user actions
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.
MVC Example
a = 50% b
b = 30%
Views c = 20% a c
a b c
Controller
See
Interact
a b c
Model 503020
[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
- Roy Fielding
Learn by Example
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
REST Fundamentals
<?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.
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.
<?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.
• Client-server
• Stateless
• Cached
• Uniform interface
• Layered system
• (Code on demand)
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
135
© Ray Renner - GWU
Publish/Subscribe Pattern
http://www.servicedesignpatterns.com/WebServiceImplementationStyles/DatasourceAdapter
CSCI 6221 – Advanced Software Paradigms
139
© Ray Renner - GWU
Idioms
License
http://creativecommons.org/licenses/by-sa/3.0/
© Ray Renner - GWU
143