ShareX/ShareX — pull request #387 by ConfusedGiant (2014-12-01 08:00:06+00:00)
Title: Implemented Strategy Pattern on Various Color Formats in ColorHelpers.cs of HelpersLib

Good evening Jaex,

This is a pull request which consists of my implementation of the Strategy Pattern on various color formats located in ColorHelpers.cs in HelpersLib.

Initially, there where methods found in the ColorHelpers.cs class which implemented color formatting logic of various types (ex: changing a color value into decimal format). While this still works, a more efficient way of implementing the same thing would be to create a Strategy Pattern.

The methods related to color formatting are all located in Colorhelpers.cs. If the Strategy Pattern is applied, the methods will be removed from ColorHelpers.cs and instead, be placed into an abstract class (to which children classes extend from) and an interface (to which classes implement). From these classes, the same methods would be called but in a more efficient way, since it lowers coupling between classes and increases maintainability for the future.

I created a generic abstract class iColorHelpers which has an association to iColorFormatType, which is a generic interface that contains the color formatting logic. The classes which extend the iColorHelpers class will be passing a runtime type to the iColorFormatType. The classes which implement iColorFormatType will contain the logic needed to convert from one color format to another.

Something worth noting, I have not removed any of the old methods located in ColorHelpers.cs, in case you would like to remove the Strategy Pattern that I implemented and keep your old code.

I hope you find this useful!

Ahmed.