Service layer
What are models? What is their life-cycle? What services does hybris have? What is the role of the Spring framework in hybris Services? ServiceLayer Interceptors Spring Framework in the hybris Commerce Suite
Structure Overview
The ServiceLayer can be described as a layer of services on top of the persistence layer. The services themselves can be divided into subcomponents. Figure: The ServiceLayer (blue) interconnects the persistence layer with the client. Arrows indicate exchange of data objects.
Architectural Components
Client
A client in this context is any software component that uses the ServiceLayer, such as:
- Page Controllers of an MVC framework
- Web Service clients
- Scripts
- Other services
Services
Figure: Sample of relations between services. Note the pattern of having an interface and an implementation per service. The hybris Commerce Suite exposes all of its functionality through services. The following kinds of services are available:
- Business Services implement business use cases, such as cart handling or back order.
- Infrastructure Services provide the underlying technical foundation, such as internationalization, import, export, and so on.
- System services provide functionality required by the ServiceLayer, such as model handling and session handling.
The service methods should be as fine-grained as possible to enable reuse. Extensions must provide their functionality as services. Per extension you may provide as many services as you deem necessary, not just one. Services may use other services to perform their tasks but should keep their interdependencies to a minimum to avoid overly tight coupling with other components. In a project, you may write your own services to either provide unique functionality or to aggregate other services’ functionality. Although technically not necessary, hybris recommends implementing services in terms of interfaces. See Spring Framework in the hybris Commerce Suite for reasons why. Services interact with other components through models. For details see section Models below.
Strategies
Figure: Sample of a service (consisting of an interface definition and the related implementation) relying on strategies. Note how the strategies also follow the pattern of interface definition and related implementation.
DAOs
A DAO (Data Access Object) is an interface to the storage back end system. DAOs store and retrieve objects. You use DAOs to save, remove, and find models. DAOs are the place to put SQL or FlexibleSearch statements and nowhere else. This is to ensure further decoupling from the underlying storage facility. DAOs interact with services via models and with the database viaFlexibleSearch and SQL statements.
- How to Add a New Service: Implementation guide
- Wikipedia on DAOs