I am currently implementing a design for an enhancement. Need your suggestions for the design.
The following are my requirements:
- I have 4 methods namely -> fetch_schema, transform_schema, stage_schema and register_schema
- I have 2 clients. 1 client should be able to override only 1 method -> transform_schema and the another client should be able to override all the methods
I thought of the following approach :
- Interface A -> Interface with default implementations (Java 8) of fetch schema, staging, register to schema registry methods
- Classes extending the interface A can override the fetch schema, staging, register to schema registry methods
- Interface B -> Interface for the transformer which contains the default implementations for transformer method
- Classes extending the interface B can override the transformer methods
In the above approach the 1st client will use only Interface B whereas the 2nd client who wants to override all the methods can use Interface A and Interface B
Sample code :
interface A {
default fetch_schema(){ // Some default implementation }
default stage_schema(){ // Some default implementation }
default register_schema(){ // Some default implementation }
}
interface B {
default transform_schema(){ // Some default implementation }
}
// Sample class used by client 1
class SampleTransformer implements B {
@Override
transform_schema(){
// Some implementation
}
}
// Sample class used by client 2
class SampleTransformer implements A,B {
@Override
fetch_schema(){
// Some implementation
}
@Override
stage_schema(){
// Some implementation
}
@Override
register_schema(){
// Some implementation
}
@Override
transform_schema(){
// Some implementation
}
}
Another approach would be :
- Interface A -> Interface with declarations of fetch schema, staging, register to schema registry methods
- Classes extending the interface A can override the fetch schema, staging, register to schema registry methods
- Interface B -> Interface for the transformer which contains the declarations for transformer method
- Classes extending the interface B can override the transformer methods
In the above approach, there will be a default bean called DefaultSchemaProcessor which extends both Interface A and B and overrides the necessary methods.
The respective clients who wants to override the methods will define their own bean and replace the DefaultSchemaProcessor.
The 1st client's bean will extend only Interface B whereas the 2nd client who wants to override all the methods can use Interface A and Interface B
Sample code :
interface A {
fetch_schema();
stage_schema();
register_schema();
}
interface B {
transform_schema();
}
// DefaultSchemaProcessor
class DefaultSchemaProcessor implements A,B {
@Override
fetch_schema(){
// Some implementation
}
@Override
stage_schema(){
// Some implementation
}
@Override
register_schema(){
// Some implementation
}
@Override
transform_schema(){
// Some implementation
}
}
// Sample class used by client 1
class SampleTransformer implements B {
@Override
transform_schema(){
// Some implementation
}
}
// Sample class used by client 2
class SampleTransformer implements A,B {
@Override
fetch_schema(){
// Some implementation
}
@Override
stage_schema(){
// Some implementation
}
@Override
register_schema(){
// Some implementation
}
@Override
transform_schema(){
// Some implementation
}
}
Do you guys have any suggestions?
Aucun commentaire:
Enregistrer un commentaire