-
Notifications
You must be signed in to change notification settings - Fork 2
Domain Use Cases
This document covers the business logic implementation and use case patterns in the Effective Office tablet client. Domain use cases represent the core business operations that the application can perform, implementing clean architecture principles by separating business logic from UI and data concerns.
For information about the data layer and repository patterns that support these use cases, see Data Layer & Repositories. For details about the overall system architecture, see System Architecture.
The domain layer contains use cases that encapsulate specific business operations such as booking management, room selection, and data synchronization. Each use case follows a single responsibility principle and coordinates between repositories to achieve business goals. The use cases are organized into distinct categories based on their functional area and are managed through dependency injection.
The domain use cases are structured in a layered architecture where use cases coordinate between repositories and implement business rules.
The booking use cases handle the core business operations for managing room reservations. These use cases follow a consistent pattern of optimistic updates with rollback capabilities.
The DeleteBookingUseCase
demonstrates the typical pattern used across booking operations:
The use case implements optimistic updates by immediately marking the event as loading in the local repository, attempting the network operation, and either completing the deletion or rolling back to the original state on failure.
The SelectRoomUseCase
implements intelligent room selection based on availability and capacity matching:
The selection algorithm prioritizes rooms that are immediately available and have similar capacity to the current room, with fallback logic for finding the nearest available time slot.
The UpdateUseCase
manages automatic data refresh timing based on upcoming events:
The use case calculates optimal update intervals by finding the minimum time until the next significant event change (either an event starting or ending), ensuring the UI stays synchronized with real-time booking changes.
The domain use cases are organized through a comprehensive dependency injection module that manages their creation and dependencies:
Use Case Category | Use Cases | Key Dependencies |
---|---|---|
Booking Operations |
CreateBookingUseCase , UpdateBookingUseCase , DeleteBookingUseCase
|
NetworkBookingRepository , LocalBookingRepository , GetRoomByNameUseCase
|
Room Information |
RoomInfoUseCase , GetRoomsInfoUseCase , GetCurrentRoomInfosUseCase
|
LocalRoomRepository , RefreshDataUseCase
|
Data Flow |
GetEventsFlowUseCase , RefreshDataUseCase
|
NetworkRoomRepository , LocalRoomRepository
|
Utility |
TimerUseCase , UpdateUseCase , SelectRoomUseCase
|
Various domain dependencies |
The RoomInfoUseCase
serves as a central coordinator that aggregates multiple data sources:
This composition pattern allows the RoomInfoUseCase
to provide comprehensive room information by coordinating multiple specialized use cases.
The main screen feature includes specialized use cases for UI-specific logic:
-
GetRoomIndexUseCase
: Manages room index calculation for display -
GetTimeToNextEventUseCase
: Calculates timing information for UI updates
These feature-specific use cases are registered in their own module and handle presentation-layer business logic.
The domain use cases implement consistent error handling using the Either
type pattern, providing structured error responses with HTTP-style status codes and descriptive messages. Failed operations attempt graceful degradation by rolling back to previous states in local repositories while preserving error information for user feedback.