Friday, April 13, 2018

"The wrapper" is a pretty good pattern for generics.

Let's say I want to have a type and then an isDirty flag with it. Well I could write a type that has T for the wrapped type, Cat, Dog, or Person or whatever, and have a getsetter for the Boolean for isDirty right? If I want to have a serializable type make its way from C# to JavaScript and also carry with it a ruleset for the RegEx for sanity checks for the fields at the forms to be used at the JavaScript side of things, that could look like a wrapper with T for the type and a getsetter for a Dictionary<string,string>. What is more, that same wrapper would work pretty good for a collection of things beyond a single item too.

No comments:

Post a Comment