core-java icon indicating copy to clipboard operation
core-java copied to clipboard

Storages and delegation

Open dmdashenkov opened this issue 4 years ago • 2 comments

Currently, it is not easy to create an implementation of, e.g. ProjectionStorage, which would delegate its operations to another instance of ProjectionStorage.

The problem is in protected methods.

package org.example;

// ...

class MyProjectionStorage<I> extends ProjectionStorage<I> {

    private final ProjectionStorage<I> delegate;

    @Override
    protected Optional<EntityRecord> readRecord(I id) {
        return delagate.readRecord(id); 
        //              ^
        // Compiler error here, cannot access protected method `readRecord`
        //  outside the Spine package.
    }
    
    // ...
}

There are a few methods in ProjectionStorage and other case-specific storages such as readRecord, which are declared protected making it impossible to delegate them.

dmdashenkov avatar Mar 03 '20 14:03 dmdashenkov

Currently, I offer to resolve this when we re-design out storages to fit all purposes with just one MessageStorage.

dmdashenkov avatar Mar 03 '20 14:03 dmdashenkov

@armiol, FYI. @nick-dolgiy, please feel free to add further details.

dmdashenkov avatar Mar 03 '20 14:03 dmdashenkov