[ Core/QBit Architecture ] - The Interface + Registry Pattern #382
KofTwentyTwo
announced in
Daily Build Log
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
[ Core/QBit Architecture ] - The Interface + Registry Pattern
When qqq-backend-core needs optional functionality from a qbit, reflection is tempting. Do not do it. Here is the pattern that actually works.
The Problem We Had
PR #381 introduced session store integration. The original approach used reflection:
This inverts the dependency direction. Core should never know about specific qbits - even reflectively.
Why reflection is wrong here:
The Pattern: Interface + Registry
The fix follows a pattern already established in QQQ (see
SpaNotFoundHandlerRegistry):Step 1: Define Interface in Core
Step 2: Create Registry in Core
Step 3: QBit Extends Interface
Step 4: QBit Registers on Startup
Step 5: Core Uses Registry with Fallback
Optimizing for Remote Stores
When your provider talks to Redis, a database, or any remote service, round-trips matter. The interface should support combined operations.
Before (two round-trips):
After (one round-trip):
The interface provides a default implementation that calls
load()thentouch(). Providers override with optimized versions:What Changed
qqq-backend-core:
QSessionStoreProviderInterface.java(new) - interface definitionQSessionStoreRegistry.java(new) - singleton registryQSessionStoreHelper.java- removed reflection, uses registryOAuth2AuthenticationModule.java- usesloadAndTouchSession()qbit-session-store:
QSessionStoreProviderInterface.java- extends core interfaceQSessionStoreQBitProducer.java- registers with core on startupInMemorySessionStoreProvider.java- addedgetDefaultTtl(),loadAndTouch()TableBasedSessionStoreProvider.java- addedgetDefaultTtl(),loadAndTouch()RedisSessionStoreProvider.java- addedgetDefaultTtl(),loadAndTouch()When to Use This Pattern
Use Interface + Registry when:
Do not use this pattern when:
Existing Registries in QQQ
SpaNotFoundHandlerRegistry- allows multiple SPAs to register 404 handlersQSessionStoreRegistry- session store provider registrationIf you are building a qbit that provides optional functionality to core, follow this pattern. It keeps the architecture clean and the dependency direction correct.
Beta Was this translation helpful? Give feedback.
All reactions