I'd like to create a class or object that represents a schema. I want my schema to be encapsulated in this object such that I only need to play around with this object to change the schema of several other objects that rely on it. Say I have several classes that inherit from IMessageFormat. One of the methods of IMessageFormat interface is FormatMessage. Now, this method may have different contents, but it will always have the same schema. For instance,
Schema
sequenceID,Direction,LocalTime,EventTime,MessageBody
If I had 50 objects that inherit from IMessageFormat, and I suddently wanted to change the schema to
productSymbol,sequenceID,Direction,LocalTime,EventTime,MessageBody
or maybe I want to change the delimeter from , to |?
I would need to make 50+ changes in 50 classes. This is tedious. What's the best way to minimize this work, such that, if I needed to add or remove a field, I can do it in one central hub? I know this question is a little broad.
Below is an implementation of FormatMessage so you can understand what I'm doing right now:
public StringBuilder FormatMessage(FixMessage fixMessage)
{
var fixDict = fixMessage.FixDictionary;
var sequenceNumber = fixDict[34][0];
var direction = fixMessage.FixMessageDirection.ToString("f");
var timestamp = fixMessage.Timestamp.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
var stringBuilder = new StringBuilder();
// First line.
stringBuilder.AppendLine($"{sequenceNumber},{direction},{timestamp}," +
$"Mass Quote: QuoteID[{fixDict[117][0]}] NoQuoteEntries[{fixDict[296][0]}]");
// Second line.
// Amount of quote sets.
int quoteSetCount = Convert.ToInt32(fixDict[302][0]);
for (int i = 1; i <= quoteSetCount; ++i)
{
int quoteEntries = Convert.ToInt32(fixDict[295][i]);
stringBuilder.AppendLine($",,{timestamp},\tQuoteSetID[{quoteSetCount}] NoQuoteEntries[{quoteEntries}]");
// Quotes in individual quote set.
for (int j = 0; j < quoteEntries; ++j)
{
stringBuilder.AppendLine($",,{timestamp},\t\tSecurityDesc[{fixDict[107][j]}] BidPx[{fixDict[132][j]}] " +
$"BidSize[{fixDict[134][j]}] OfferPx[{fixDict[133][j]}] OfferSize[{fixDict[135][j]}]");
}
}
return stringBuilder;
}
Aucun commentaire:
Enregistrer un commentaire