d.Service Layer
Motivation
To write a webservice wrapper over business logic usually for out of process communication.
Summary
A Service Layer defines an application's boundary and its set of available operations from the perspective of interfacing client layers.
It encapsulates the application's business logic, controlling transactions and coordinating responses in the implementation of its operations.
A business logic is usually of two type Domain Logic (Core Business Components like business rules) and application logic like notification service and service layer in general expose the application logic as out process service.
When to Use
When you need to expose application logic (businesss logic=Domain Logic+application Logic) as a saparate subsystem mostly out of proc.
Implementation
The two basic implementation variations are the domain facade approach and the operation script approach.
Domain Facade
In the domain facade approach a Service Layer is implemented as a set of thin facades over a Domain Model.
The classes implementing the facades don't implement any business logic.
The thin facades establish a boundary and set of operations through which client layers interact with the application, exhibiting the defining characteristics of Service Layer.
Operation Script
In the operation script approach a Service Layer is implemented as a set of thicker classes that directly implement application logic but delegate to encapsulated domain object classes for domain logic.
The operations available to clients of a Service Layer are implemented as scripts, organized several to a class defining a subject area of related logic.
Each such class forms an application "service," and it's common for service type names to end with "Service." A Service Layer is comprised of these application service classes, which should extend a Layer Supertype, abstracting their responsibilities and common behaviors.
Example
TODO
Related Patterns
Domain Model
Transaction Scripts
Specific Considerations
Remote Vs Local
Preferable we should start working on service layer implementation that directly invoke business object.
Ten prefer to write a thin facade on local layer applications and clients that needs to access it out of proc.
This allow in proc application to take advantage of in proc performance.
References
Overview Tutorials
Other References