mardi 28 juin 2016

Open/Close principle violates YAGNI principle

I have been developing a piece of library in C#, The primary aim of this library is to wrap all the versions of default linux binaries like ifconfig, dmidecode etc, assuming at least any one of their version will be present in any linux distribution.

All the wrappers are expected to return Tuples of the type Tuple<string, ExtractedInfoType> where string is the original string resulted from the execution of the command and ExtractedInfoType is the data which we expect from the wrapper in the form of class or struct.

The reason why I chose to return Tuple which contain both original information and the extracted information rather than just returning the extracted information is I want to throw away the original information as lazy as possible, so that if I have any other means to extract more information I can just extract from left string to right ExtractedInfoType in the tuple by just decorating the class with another class which I believe enforces open/close principle, Since I don't want to change the original class when I need to extend the functionality.

On a side note I feel it violates YAGNI principle since I may not extend the class altogether it may be the one and only class which will never be decorated again. In that case I am writing some code say this in quotes"Tuple<string",ExpectedInfoType> is the extra code that I may never need.

I may be taking things too literally, but for me both principles are in some contradiction here.

Aucun commentaire:

Enregistrer un commentaire