Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design...
Transcript of Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design...
![Page 1: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/1.jpg)
Service Layer Design“Facade Vs. Command”
![Page 2: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/2.jpg)
Client Tier thick thin
Presentation Tier controller
service
Business tier
service service service
controller controller
Service layer
DAO DAO DAOData access layer
Persistence Tier
Introduction
![Page 3: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/3.jpg)
Client Tier
Presentation Tier HTTP Servlet
Business tier
loginService layer
User DAOData access layer
Persistence Tier
web service
time of day
Introduction
![Page 4: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/4.jpg)
Facade Pattern
Intent● “provide a unified interface to a set of interfaces in a
subsystem”
Facade
![Page 5: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/5.jpg)
Facade Example
Facade pattern: http://en.wikipedia.org/wiki/Facade_pattern
![Page 6: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/6.jpg)
Facade Example
![Page 7: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/7.jpg)
Facade Pattern
Advantages● looser coupling● lower network communication
– in enterprise application each method call incurs communication latency
● provides an extension point– add security, logging
● promotes reusability– unit of (business) work
● simple to understand & implement
![Page 8: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/8.jpg)
Facade Pattern
Disadvantages● Evolution
– facade methods are written in stone● 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/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/9.jpg)
Facade Pattern
Disadvantages● Re-usability
– change in execution environment– aggregation of facade methods
![Page 10: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/10.jpg)
Command Pattern
Intent● “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
![Page 11: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/11.jpg)
Command Example
![Page 12: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/12.jpg)
Command ExampleA switch can be associated with any other component by simply injecting the appropriate commands for flip up and flip down
![Page 13: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/13.jpg)
Command as Service Layer
![Page 14: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/14.jpg)
Command as Service Layer
Observation● 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 15: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/15.jpg)
Command as Service Layer
![Page 16: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/16.jpg)
Command as Service Layer
Evolution● 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
![Page 17: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/17.jpg)
Command as Service Layer
Scalability● 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 18: Service Layer Design “Facade Vs. Command”a78khan/courses-offered/... · Service Layer Design “Facade Vs. ... Data access layer Persistence Tier Introduction. Client Tier Presentation](https://reader036.fdocuments.us/reader036/viewer/2022081613/5fbcab727cf40333010d3e74/html5/thumbnails/18.jpg)
Command as Service Layer
Re-usability● commands are simple and 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