service layer design “facade vs. command”a78khan/cs446/additional... · service layer design...

20
WATERLOO CHERITON SCHOOL OF COMPUTER SCIENCE Service Layer Design Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These slides are NOT to be used as a replacement for student notes. These slides are sometimes vague and incomplete on purpose to spark class discussions

Upload: others

Post on 16-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Service Layer DesignService Layer Design“Facade Vs. Command”

CS 446/646 ECE452[DATE]

IMPORTANT NOTICE TO STUDENTS

These slides are NOT to be used as a replacement for student notes.These slides are sometimes vague and incomplete on purpose to spark class discussions

Page 2: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

2WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Introduction

Client Tier thick thin

Presentation Tier controller

service

Business tier

service service service

controller controller

Service layer

DAO DAO DAOData access layer

Persistence Tier

Page 3: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

3WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Introduction

Client Tier

Presentation Tier HTTP Servlet

Business tier

loginService layer

User DAOData access layer

Persistence Tier

web service

time of day

Page 4: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

4WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

FacadeIntent● “provide a unified interface to a set of interfaces in a

subsystem”

Considerations- inter component coupling- system evolution - fault-tolerance

creational? structural? behavioural?

Page 5: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

5WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

FacadeIntent● “provide a unified interface to a set of interfaces in a

subsystem”

Facade

Page 6: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

6WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Example

Facade pattern: http://en.wikipedia.org/wiki/Facade_pattern

Page 7: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

7WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Facade PatternAdvantages● looser coupling● lower network communication

– in enterprise application each method call incurs communication latency

● provides an extension point (how?)– security, logging

● promotes reusability– unit of (business) work

● simple to understand & implement

Page 8: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

8WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Facade PatternDisadvantages● Evolution

– facade methods are written in stone (why?)● Scalability

– addition of new methods– deprecation of old methods– facade becomes complicated itself

● error reporting/handling● does not grow organically

Page 9: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

9WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Facade PatternDisadvantages● Re-usability

– change in execution environment– aggregation of facade methods

Page 10: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

10WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Facade based Service Layer Class Activity● identify facade

– login– change password

Page 11: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

11WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Login Example

Page 12: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

12WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command PatternIntent● “encapsulate the request as an object...”

So what● how does the execution change?

– can we serialize objects?– can we aggregate requests (commands)?

● separation of concerns– caller object from the execution object

● dynamic in nature– commands can be replaced at runtime (why?)

Page 13: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

13WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Pattern

where is the functional logic implemented here?

Page 14: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

14WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Pattern

A switch can be associated with any other component by simply injecting the appropriate commands for flip up and flip down

Page 15: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

15WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Service Layer

Page 16: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

16WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Service LayerObservation● if commands represent business functionality then how

come they are exposed to the client?● in tiered applications, how do we deal with the

marshalling and demarshalling of commands objects?– expensive to move 'heavy duty' objects

Page 17: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

17WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Service Later

Page 18: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

18WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Service LaterEvolution● defining new commands is trivial● deprecating commands is easy

– only need to retain the command identifier

Unit of work● each unit of work is a command● what was the unit of work in facade?

Page 19: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

19WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command Service LaterScalability● as the system grows we only add new concrete

implementations● more control over execution environment● can I merge two or more commands into a single

execution unit – composite command?

Page 20: Service Layer Design “Facade Vs. Command”a78khan/cs446/additional... · Service Layer Design “Facade Vs. Command” CS 446/646 ECE452 [DATE] IMPORTANT NOTICE TO STUDENTS These

20WATERLOOCHERITON SCHOOL OFCOMPUTER SCIENCE

Command as Service LayerRe-usability● commands are simple & hence can be used in many

different ways– single command– command chains (aggregation)– composite command

Testing● easy to test

– due to the separation of concerns