Top Banner
Client/Server Software Architectures Yonglei Tao
25

Client/Server Software Architectures Yonglei Tao.

Dec 24, 2015

Download

Documents

Dale Payne
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Client/Server Software Architectures Yonglei Tao.

Client/Server Software Architectures

Yonglei Tao

Page 2: Client/Server Software Architectures Yonglei Tao.

Overview

Page 3: Client/Server Software Architectures Yonglei Tao.

Multi-Client/Multi-Service

Page 4: Client/Server Software Architectures Yonglei Tao.

Design Issues1. Support communication between clients and

servers 2. Hide details of the communication

mechanism• The proxy pattern

3. Manage various service requests• The façade pattern

4. Support services that need access to databases

• Wrapper classes (the Adapter pattern)

Page 5: Client/Server Software Architectures Yonglei Tao.

1. Support Communication Synchronous message communication with

reply

Asynchronous message communication with callback

Page 6: Client/Server Software Architectures Yonglei Tao.

2. Hide Communication Mechanism Problem

Direct access to a real subject is not desirable or possible

The proxy pattern Provides a local representative for an object in a

different address space Hides details of accessing the real object (used

in Java RMI)

Page 7: Client/Server Software Architectures Yonglei Tao.

The Proxy Pattern

Client

+makeRequest()-s : ISubject

«Interface»ISubject

+request()

Proxy

+request()-r : ISubject

RealSubject

+request()

1

1

1

1

void makeRequest () { s.Request(); ...}

void request () { r.request(); ...}

Page 8: Client/Server Software Architectures Yonglei Tao.

The Proxy Pattern Adding a level of indirection with a surrogate

for the real subject to control access to it A proxy is an object with the same interface

as the real object it represents A client object interacts with the proxy even

it intends to talk to the real object The proxy forwards a request from a client

object to the real object to fulfill the request

Page 9: Client/Server Software Architectures Yonglei Tao.

Proxy - Applicability Protection proxy

Provide different objects with different level of access to the original object

Protect local clients from outside world as a firewall

Virtual proxy Create/access expensive objects on demand

Page 10: Client/Server Software Architectures Yonglei Tao.

Middleware as Proxy Provides standard services to software applications such as RPC, RMI, COM, CORBA, etc.

Page 11: Client/Server Software Architectures Yonglei Tao.

3. Manage Service Requests Problem

How to provide a unified interface to a set of interfaces within a subsystem

Using the Façade pattern Define a single entry point to the subsystem (a

facade object that wraps the subsystem) Let it be responsible for coordinating subsystem

components Clients interface the facade class to deal with

the subsystem

Page 12: Client/Server Software Architectures Yonglei Tao.

The Façade Pattern

Client 1

C lient 2

C leint 3

subsystem s subsystem s

Client 1

C lient 2

C lient 3

Facade

Page 13: Client/Server Software Architectures Yonglei Tao.

Façade – an Example

Page 14: Client/Server Software Architectures Yonglei Tao.

Façade - Consequences A high-level interface that makes

subsystem easy to use and more independent Hide implementation of the subsystem from

clients It reduces coupling between a subsystem

and its clients A Façade class does not add new

functionality to the subsystem

Page 15: Client/Server Software Architectures Yonglei Tao.

Manage Service Requests

(1) Sequential Service Using a single object to handle various

requests from clients A coordinator object or façade

Processing client requests one by one Client uses synchronous message communication

with reply to raise a request

Page 16: Client/Server Software Architectures Yonglei Tao.

Manage Service Requests

(2) Concurrent Service Sharing service functionality among several

concurrent objects Processing multiple client requests

concurrently Client uses asynchronous message

communication with callback to raise a request On completion, the responsible object remotely

invokes the callback Used where client demand for services is high

Improve throughput

Page 17: Client/Server Software Architectures Yonglei Tao.

4. Needs for Database Services Query

View data Perform computations on the data Send data from one place to another

Manipulation Add, modify, and delete data

Logging Activities on the server Interactions with the database

Page 18: Client/Server Software Architectures Yonglei Tao.

From a Static Model to a Relational Database Mapping an entity class to a relational table

Relate attributes to columns, objects to rows Identify primary key

Mapping associations to foreign keys One-to-one, zero-to-one, and one-to-many

Mapping association classes Mapping a whole/part relationship

Composite and aggregate Mapping a generalization/specialization

relationship Superclass and Subclasses together Subclasses Only Superclass Only

Page 19: Client/Server Software Architectures Yonglei Tao.

Database Wrapper Classes Entity classes

Likely to be designed on the client side Occasionally used to temporarily store data on the

server side Database wrapper classes

Manage the data that is stored in a database Primarily designed on the server side Provides object-oriented interface to the database Hides how the data is accessed and maintained

Page 20: Client/Server Software Architectures Yonglei Tao.

The Adapter Pattern Problem

How to resolve incompatible interfaces or provide a stable interface to similar components with different interfaces

Solution Convert the original interface of a component

into another interface, through an intermediate adapter object

Also known as Wrapper

Page 21: Client/Server Software Architectures Yonglei Tao.

Motivation Sometimes a toolkit or third party system

cannot be used because its interface is incompatible with the interface required by an application

We cannot change the system Even if we can we probably should not do

for each domain-specific application

Page 22: Client/Server Software Architectures Yonglei Tao.

Structure

Page 23: Client/Server Software Architectures Yonglei Tao.

Example of Using Adapter In the original CGI web server programs

CGIVariables ref = …;

ref.get(x); ref.get(y);

A new version of the web server supports servlets, which provide similar functionality but are more efficient

HttpServletRequest ref = …;

ref.getX();ref.getY();

Should we rewrite all of the existing CGI programs in order to use servlets? Want to minimize rewriting

Page 24: Client/Server Software Architectures Yonglei Tao.

Example (Cont.) Design a CGIAdapter class

Has the same interface as the original CGIVariables class Serves a wrapper around the HttpServletRequest class Allow to use servlets with a CGI like interface

Modify code

CGIVariables ref = …;

ref.get(x);

ref.get(y);

CGIAdapter

Page 25: Client/Server Software Architectures Yonglei Tao.

Consequences Provide a consistent interface within an

application Allow to change external components

without affecting the clients Introduce a level of indirection – extra

overhead