开发者

Common Framework for encoding & Decoding

I'm developing an application which uses database.

Before storing the values into database, I'm doing some encoding on data. While Retriving the data, I've to do reverse encoding to get back the original data.

For this purpose, I've created one class with various fields h开发者_开发技巧olding value and one method for encoding & one method for decoding.

The problem with this kind of encoding method, according to me, is that in the future, if I'm using some different method of encoding then I'll have to write both encoding & Decoding method.

The encoding & Decoding methods are very much simple transformation converting 3D array into a list of Strings..

Can any one suggest me any better way of same problem ???


Yes - employ SRP with abstraction.

You abstract away the encoder and decoder into a different interface. Then use composition in your data holder class to reference to Encoder/Decoder. If you are using DI then the encoder/decoder would be injected w/o data holder having knowledge of the actual implementation. Or have a service that would take data holder instance and apply encoder/decoder based on the implentation attached (done again using DI) with that service.

Hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜