You are on page 1of 32

SENG 307

Software Architecture - Design Patterns


Software Architecture Patterns
• The idea of patterns as a way of presenting, sharing, and reusing knowledge about.
• You can think of an architectural pattern as a stylized, abstract description of good practice, which
has been tried and tested in different systems and environments.
• So, an architectural pattern should describe a system organization that has been successful in
previous systems.
• It should include information of when it is and is not appropriate to use that pattern, and the
pattern’s strengths and weaknesses.
• The patterns include:
Layered pattern
Client-server pattern
Master-slave pattern
Pipe-filter pattern
Broker pattern
Peer-to-peer pattern
Event-bus pattern
Model-view-controller pattern
Blackboard pattern
Interpreter pattern
Layered Pattern
Description
• Layered architecture patterns are n-tiered patterns where the components
are organized in horizontal layers.
• This is the traditional method for designing most software and is meant to be
self-independent, where all the components are interconnected but do not
depend on each other.
• The outermost layer is where the data enters the system. The data passes
through the subsequent layers to reach the innermost layer, which is the
database layer.
• Simple implementations of this pattern have at least 3 layers, namely, a
presentation layer, an application layer, and a data layer. Users access the
presentation layer using a GUI, whereas the application layer runs the
business logic. The data layer has a database for the storage and retrieval of
data.
Layered Pattern
Layered Pattern
When Used
Layered architecture is widely used for numerous reasons. You can consider it under the
following scenarios/requirements:

• When you aim to design an application quickly with fewer developers.

• Applications that primarily require maintainability and separation of concerns as their pillars of
architecture.

• Enterprise applications that need to adopt traditional IT structures and processes.

• when building new facilities on top of existing systems

• when the development is spread across several teams with each team responsibility for a layer of
functionality

• When there is a requirement for multi-level security.


Layered Pattern
Applications/Examples
1. Enterprise resource planning (ERP).
2. Control system for self- driving vehicles.
3. Online banking website.
4. Java EE Framework.
Layered Pattern
Advantages

1. Layers are autonomous: A group of changes in one layer does not affect the
others.
2. Layers allow better system customization.
3. Maintaining the software is easy since the tiers are segregated.
4. Development teams find it easy to manage the software infrastructure,
therefore, it’s easy to develop large-scale web and cloud-hosted apps.
Layered Pattern
Disadvantages
1. The code can become too large.
2. A considerable part of the code only passes data between layers instead of
executing any business logic, which can adversely impact performance.
3. Layers make an application more difficult to maintain. Each change requires
analysis.
4. Layers may affect application performance because they create overhead in
execution: each layer in the upper levels must connect to those in the lower
levels for each operation in the system.
Client-server pattern
Description
• In a client–server architecture, the functionality of the system is organized
into services, with each service delivered from a separate server.
• Clients are users of these services and access servers to make use of
them.
• Client components send requests to the server, which processes them
and responds back.
• When a server accepts a request from a client, it opens a connection with
the client over a specific protocol.
• Servers can be stateful or stateless. A stateful server can receive multiple
requests from clients. It maintains a record of requests from the client,
and this record is called a ‘session’.
Client-server pattern
Client-server pattern
When Used
1. when data in a shared database has to be accessed from a range of
locations.
2. Because servers can be replicated, may also be used when the load
on a system is variable.
Client-server pattern
Applications/Examples
1. Mail server
2. Print server
3. Web server
4. DNS
5. File server
Client-server pattern
Advantages

1. Clients access data from a server using authorized access, which improves
the sharing of data.
2. Accessing a service is via a ‘user interface’ (UI), therefore, there’s no need
to run terminal sessions or command prompts.
3. Client-server applications can be built irrespective of the platform or
technology stack.
4. This is a distributed model with specific responsibilities for each
component, which makes maintenance easier.
5. The principal advantage of this model is that servers can be distributed
across a network.
Client-server pattern
Disadvantages
1. The server can be overloaded when there are too many requests.
2. A central server to support multiple clients represents a ‘single
point of failure’.
3. Performance may be unpredictable because it depends on the
network as well as the system.
Pipe-filter pattern
Description
1. It lays emphasis on the incremental transformation of data by
successive component. In this approach, the flow of data is driven by
data and the whole system is decomposed into components of data
source, filters, pipes, and data sinks.
2. The connections between modules are data stream which is first-
in/first-out buffer that can be stream of bytes, characters, or any other
type of such kind. The main feature of this architecture is its concurrent
and incremented execution.
3. The code for each task is relatively small. It is treated as one
independent ‘filter’.
4. You can deploy, maintain, scale, and reuse code in each filter.
5. The stream of data that each filter processes pass through ‘pipes’.
Pipe-filter pattern
Pipe-filter pattern
When Used
1. When there is a complex processing that needs to be broken into
separate tasks and processed separately.
2. Commonly used in data processing applications (both batch- and
transaction-based) where inputs are processed in separate stages to
generate related outputs.
Pipe-filter pattern
Applications/Examples
1. Compilers
2. Text-based utilities in the UNIX operating system (pipe command) .
Pipe-filter pattern
Advantages
1. Provides concurrency and high throughput for excessive data
processing.
2. Provides reusability and simplifies system maintenance.
3. Provides modifiability and low coupling between filters.
4. Provides simplicity by offering clear divisions between any two
filters connected by pipe.
5. Provides flexibility by supporting both sequential and parallel
execution.
Pipe-filter pattern
Disadvantages
1. This pattern is complex.
2. Data loss between filters is possible in case of failures unless you use a
reliable infrastructure.
3. Not suitable for dynamic interactions.
4. A low common denominator is needed for transmission of data in ASCII
formats.
5. Overhead of data transformation between filters.
6. Does not provide a way for filters to cooperatively interact to solve a
problem.
7. Difficult to configure this architecture dynamically.
Peer-to-peer pattern
Description
1. “Peer-to-peer (P2P) pattern” is markedly different from the client-server
pattern since each computer on the network has the same authority.
2. P2P may also be used to refer to a single software program designed so that
each instance of the program may act as both client and server, with the same
responsibilities and status.
3. There isn’t one central server, with each node having equal capabilities.
4. Each computer can function as a client or a server.
5. When more computers join the network, the overall capacity of the network
increases.
6. The data is exchanged over TCP IP just like it happens over the HTTP protocol
in a client-server model. The P2P design over TCP IP enables the users to
connect directly & takes care of all the complexities and the heavy lifting.
Peer-to-peer pattern
Peer-to-peer pattern
When Used
1. In a computer networking architecture where each workstation, or
node, has the same capabilities and responsibilities.
2. There is need for content distribution such as software publication
and distribution, content delivery networks, streaming media and
peercasting for multicasting streams, which facilitates on-demand
content delivery.
Peer-to-peer pattern
Applications/Examples
1. File-sharing networks i.e. BitTorrent network. The underlying
architecture when sharing & downloading data via torrent files
2. Cryptocurrency networks i.e Bitcoin
3. Instant messaging
4. Voice Communication
5. Collaboration
6. High Performance Computing
Peer-to-peer pattern
Advantages
1. P2P networks are decentralized; therefore, they are more secure. i.e the security of the
Bitcoin network.
2. Hackers can’t destroy the network by compromising just one server.
3. Low latency – With low latency come better response times and shorter waiting times
between requests.
4. High bandwidth – A peer-to-peer network provides you with high bandwidth, so there
is no need for central servers to provision resources.
5. Low cost – Due to the fact that there is no central server in a peer-to-peer network,
each peer is responsible for storing and sending the requested information. There are
no fees charged by the server that is hosting the application.
6. High security – A peer-to-peer network has no single point of failure. If one node goes
offline or becomes unavailable, the network is still able to function.
7. Fault tolerance – Peer-to-peer networks are very resilient to faults. When one node
goes down, other nodes will cover for this node and keep the network running.
Peer-to-peer pattern
Disadvantages
1. Under heavy load, the P2P pattern has performance limitations.
2. P2P networks introduce many security concerns. If one peer is
infected with a virus and uploads a chuck of the file that contains
the virus, it can quickly spread to other peers.
3. Also, if there are many peers in the network, it can be difficult to
ensure they have the proper permissions to access the network if a
peer is sharing a confidential file.
Model-view-controller pattern
Description
1. Model-View-Controller (MVC) architecture pattern involves separating an applications’ data
model, presentation layer, and control aspects. There are three building blocks here,
namely, model, view, and controller.
2. The application data resides in the model.
3. Users see the application data through the view, however, the view can’t influence what the
user will do with the data.
4. The controller is the building block between the model and the view. View triggers events,
subsequently, the controller acts on it. The action is typically a method call to the model and
the response is shown in the view.

Model - Model represents an object or JAVA POJO carrying data. It can also have logic to update controller if its data changes.

View - View represents the visualization of the data that model contains.

Controller - Controller acts on both model and view. It controls the data flow into model object and updates the view
whenever data changes. It keeps view and model separate.
Model-view-controller pattern
Model-view-controller pattern
When Used
1. When there is need to separate application's concerns into different
objects. i.e. breaking up the frontend and backend code into
separate components.
Model-view-controller pattern
Applications/Examples
1. Web application frameworks like Django, Spring and Rails
2. Java SE application design
Model-view-controller pattern
Advantages
1. Using this model expedites the development because multiple
developers can work simultaneously on the model, controller and
views..
2. Development teams can present multiple views to users.
3. Changes to the UI is common in web applications, however, the
MVC pattern doesn’t need changes for it.
4. The model doesn’t format data before presenting to users,
therefore, you can use this pattern with any interface.
Model-view-controller pattern
Disadvantages
1. With this pattern, the code has new layers, making it harder to
navigate the code.
2. There is typically a learning curve for this pattern, and developers
need to know multiple technologies.

You might also like