Enterprise Software

Coarse-grained interfaces enable service composition in SOA

Service composition lets you develop business processes, applications, and complex services using simpler services from diverse environments. Here's a look at the key role played by coarse-grained interfaces.


One of the primary benefits of service-oriented architecture (SOA) is the ability to compose applications, processes, or more complex services from other less complex services. This activity, sometimes called service composition, allows developers to compose applications and processes using services from heterogeneous environments without regard to the details and differences of those environments. This SOA feature depends greatly on the services being constructed and exposed with coarse-grained interfaces.

Service granularity
Service granularity refers to the scope of functionality a service exposes. Fine-grained services might be services that provide a small amount of business-process usefulness, such as basic data access. Slightly more coarse-grained services might provide rudimentary operations, which are valuable to system experts, but are not of much value to a business-process expert. Services of the most value to business experts are constructed from lower-level services, components, and objects that are intelligently structured to meet specific business needs. These coarse-grained services can be created from one or more existing systems by defining and exposing interfaces that meet business-process requirements.

Levels of granularity
As Figure A illustrates, the level of granularity generally depends on the purpose of the software entity. The level of granularity for services tends to be coarser than the level of granularity for objects or components. A service typically exposes a single, discrete business process.

Figure A
Degrees of granularity


Services as composite interfaces
Using coarse-grained interfaces, a system of services controls access to the objects referenced by each service. While each service may be implemented as an abstraction on a group of finer-grained objects, the objects themselves can be hidden from public access. Each service can be implemented by grouping objects, components, and fine-grained services, and exposing them as a single unit through the use of facades or interfaces, as shown in Figure B.

Figure B
Coarse-grained services


Effective service interfaces
To be completely effective to a business expert, service interfaces should clearly articulate the business operations they perform as well as the required input parameters, possible errors or exceptions, and results. Service interfaces should be easily understood by business experts who do not necessarily possess in-depth technical skills. This allows business experts to use the services productively to compose business processes and applications. Figure C illustrates the associations between interface granularity and business-process composition and how these associations affect the roles of system experts and business experts.

Figure C
Service composition


A simple example
To illustrate the concept of coarse-grained interfaces, let's take a couple of simple objects and compose a more useful business service out of them by applying a new facade. Assume that we have one class called UserInfo and another class called UserAccount. We can make a useful business process, getUserAccounts, out of these classes by abstracting a new interface to represent the process. We'll use Java as our target development language.

The code in Listing A defines a simple UserInfo class, and the code in Listing B defines a simple UserAccount class.
 
Now, let’s define the service interface containing our getUserAccounts business process:
package com.jeffhanson.services;

public interface FinanceServices
{
   public UserAccount[] getUserAccounts(UserInfo userInfo);
}


With our interface in place, we can now compose instances of our two classes into a useful business process, getUserAccounts, as shown in Listing C.

Service composition
Service composition allows you to compose applications and processes using services from heterogeneous environments without regard to the details and differences of those environments. Service composition is much more achievable if the services are constructed with coarse-grained interfaces. With a palette of effectively designed and composed coarse-grained services, a business expert can productively compose new business processes and applications.

Editor's Picks