we have 3 Types of Objects that we have mapped into a single DynamoDB table.
Class A{
String a;
String b;
string c;
}
Class B{
String a; // attribute also present in A
String d;
}
Class C{
String a; // attribute also present in A and B
String d; // attribute also present in B
String e;
}
Class DynamoDbTableData{
String partitionKey; // needs to be generated by prefixing (A#, B# or C#) with some attribute based on which Class(A,B,C) Object client creates
String sortKey; //gets generated by combining multiple attributes from which class(A,B,C) object client creates
String TypeOfData; // Store A,B,C based on which class object client creates
String createdDate; // automatically generate when object of any class(A,B,C)created
String a;
String b;
String c;
String d;
String e;
}
Now we don't want to expose DynamoDbTableData Class directly to clients but the Client will only be able to access individual Classes (A,B,C) and based on that we want to map that data to the DynamoDbTableData and create partitionkey, sortKey, typeofData and createdDate entry and return DynamoDbTableData's object back to the client so that client can insert the data into DynamoDB.
Basically, We don't want the client to know the logic for partitionkey and sortKey generation and map data from particular class A,B,C directly to DynamoDbTableData and return this object.
What's the best way to model this kind of scenario, should we use inheritance (but there are some common properties in Classes, how to take care of that in inheritance) or there's some other design pattern we should be using?
Also what's the best way to copy attributes from Class A,B,C to DynamoDbTableData without much boilerplate code (possible via lombok or Apache Commons?)
Thanks in advance. We are using Spring boot and aws-sdk-java
Aucun commentaire:
Enregistrer un commentaire