> For the complete documentation index, see [llms.txt](https://admincode.gitbook.io/admincode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://admincode.gitbook.io/admincode/basics/newpage/step-3-creating-the-service-class-optional.md).

# Step 3: Creating the Service class (Optional)

The service layer in a Java application acts as an intermediary between the presentation layer (such as the user interface) and the data access layer (such as the database). In our example, it will interact with the bussiness class created from previous step.&#x20;

It encapsulates the business logic and serves as a bridge to orchestrate the flow of data between these layers. The service layer typically contains the core functionality of the application, including data validation, processing, and the implementation of business rules. By centralizing the business logic, the service layer promotes reusability, maintainability, and testability, as it allows the logic to be decoupled from the other layers. It also facilitates better organization of the codebase by isolating complex operations, making the application more scalable and easier to understand.

***Optional: Creating a new Service class might be reduntant for basic operations, since CRUD operations Create/Update/Delete are supported from the existing*****&#x20;CRUDService**.***class***

```java
package com.rce.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.rce.businessobject.*;

@Component
public class ArticleService extends BaseService {
	
	@Autowired
	private ArticleBO ArticleBO;
	
	public int countArticles() throws Exception {
	   return ArticleBO.loadAll().size();		
	}
}
```
