Service Module
A standalone OSGi service (business logic) that can be consumed by other modules.
- Encapsulate reusable logic (e.g., “EmailNotificationService”).
- Follow SOLID principles (single responsibility).
Implementation
Section titled “Implementation”Create the Module
Section titled “Create the Module”blade create -t service notification-serviceDefine the Service
Section titled “Define the Service”@Component(service = NotificationService.class)public class NotificationService { public void sendEmail(String to, String subject, String body) { // Logic to send emails System.out.println("Email sent to: " + to); }}Use the Service in Another Module
Section titled “Use the Service in Another Module”// In another module (e.g., a portlet)@Referenceprivate NotificationService _notificationService;
public void notifyUser(User user) { _notificationService.sendEmail( user.getEmailAddress(), "Welcome!", "Thanks for signing up." );}Use Cases
Section titled “Use Cases”- Reusable Utilities: Logging, notifications, validations.
- Modular Design: Decouple business logic from UI.