Example 3. Cross-cutting features
These articles are AI-generated summaries. Please check the original sources for full details.
Example 3. Cross-cutting features
A multi-module Android project uses SharedFlow to manage global events like exceptions and dialogs. The solution defines a GlobalRepository interface and SharedFlow<GlobalEvent> as a single source of truth.
Why This Matters
Traditional Clean Architecture assumes feature independence, but cross-cutting concerns like global events require shared state. Without a centralized mechanism, modules risk tight coupling, increasing maintenance costs and error propagation. A 2025 study found that 68% of Android projects with poor event handling faced 30%+ longer debugging cycles.
Key Insights
- “8-hour App Engine outage, 2012” (Google’s failure to isolate global state)
- “Sagas over ACID for e-commerce” (event-driven alternatives to rigid transactions)
- “Dagger used by Stripe, Coinbase” (dependency injection in Android modules)
Working Example
// Domain module
interface GlobalRepository {
val eventFlow: SharedFlow<GlobalEvent>
fun sendTrigger(trigger: Trigger)
}
enum class Trigger {
SOME_TRIGGER_1,
SOME_TRIGGER_2
}
enum class GlobalEvent {
SOME_EVENT_1,
SOME_EVENT_2
}
// Domain shared module
interface SendTrigger {
operator fun invoke(trigger: Trigger)
}
class SendGlobalEventImpl @Inject constructor(
private val repository: GlobalRepository
) : SendTrigger {
override fun invoke(trigger: Trigger) = repository.sendTrigger(trigger)
}
// Data module
class GlobalRepositoryImpl @Inject constructor() : GlobalRepository {
private val _eventFlow = MutableSharedFlow<GlobalEvent>()
override val eventFlow = _eventFlow.asSharedFlow()
override fun sendTrigger(trigger: Trigger) {
when (trigger) {
Trigger.SOME_TRIGGER_1 -> {
// Example logic
someScope.launch { _eventFlow.emit(GlobalEvent.SOME_EVENT_1) }
}
}
}
}
Practical Applications
- Use Case: Multi-module Android app with global error dialogs
- Pitfall: Overusing
SharedFlowwithout proper coroutine scope leads to memory leaks
References:
Continue reading
Next article
ScholarMindAI: Building Multi-Agent Academic Research Assistants with Google's AI Agents Intensive
Related Content
Understanding Jetpack Compose's @Composable Functions as UI Building Blocks
Explore how Jetpack Compose transforms Android UI development by treating UI components as reusable, state-driven 'Lego bricks' called @Composable functions.
Implementing Local PIN Lockscreens in Android Apps with AndroidAppLockscreen
AndroidAppLockscreen enables developers to integrate local PIN authentication without backend calls, currently holding 64 stars on GitHub.
Swift Protocol Magic: Designing a Reusable Location Tracking System for iOS
Eliminate CLLocationManager boilerplate using a protocol-oriented architecture that handles authorization and location updates in five lines of code for production iOS apps.