LordNed/WArchive-Tools

Use Polymorphism for Encoding/Decoding?

Closed this issue · 2 comments

This one is more 'good programming practices' than 'directly needed by the project'. Instead of having switch statements everywhere and unique function names for every encoding/decoding thing, perhaps we should use polymorphism and interfaces to do decoding.

Pros:
More flexible and easier to support more formats in the future.

Cons:
Raises code complexity.

Example:
IFileDecompressor decompressor = new Yay0Decompressor();
RARC archive = new RARC();
archive.ReadFile(decompressor.Decompress(fileStream));

Where there would also be implementations of Yaz0Decompressor, and UncompressedDecompressor.

I'm going to table this one as it sounds like unneeded complexity in retrospect.

My programming expertise is lacking, but I believe it's best we use switches for compression. It makes the code clearer, at least. And we're really only going to need the compression code twice - once for decompression (if needed), and one for recompression.

Unless we want to enable de/recompression of individual files, which does happen for example with the images and screen layout files in TWW. Then we might want to find a better solution, if one exists.

Retrospect: This is over-complication. Thanks for the thoughts.