Note that there are some explanatory texts on larger screens.

plurals
  1. POClass design: file conversion logic and class design
    text
    copied!<p>This is pretty basic, but sort of a generic issue so I want to hear what people's thoughts are. I have a situation where I need to take an existing MSI file and update it with a few standard modifications and spit out a new MSI file (duplication of old file with changes).</p> <p>I started writing this with a few public methods and a basic input path for the original MSI. The thing is, for this to work properly, a strict path of calls has to be followed from the caller:</p> <pre class="lang-cs prettyprint-override"><code>var custom = CustomPackage(sourcemsipath); custom.Duplicate(targetmsipath); custom.Upgrade(); custom.Save(); custom.WriteSmsXmlFile(targetxmlpath); </code></pre> <p>Would it be better to put all the conversion logic as part of the constructor instead of making them available as public methods? (in order to avoid having the caller have to know what the "proper order" is):</p> <pre class="lang-cs prettyprint-override"><code>var custom = CustomPackage(sourcemsipath, targetmsipath); // saves converted msi custom.WriteSmsXmlFile(targetxmlpath); // saves optional xml for sms </code></pre> <p>The constructor would then directly duplicate the MSI file, upgrade it and save it to the target location. The "WriteSmsXmlFile is still a public method since it is not always required.</p> <p>Personally I don't like to have the constructor actually "do stuff" - I prefer to be able to call public methods, but it seems wrong to assume that the caller should know the proper order of calls?</p> <p>An alternative would be to duplicate the file first, and then pass the duplicated file to the constructor - but it seems better to have the class do this on its own.</p> <p>Maybe I got it all backwards and need two classes instead: <strong>SourcePackage</strong>, <strong>TargetPackage</strong> and pass the SourcePackage into the constructor of the TargetPackage?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload