To demonstrate how to use the factory method pattern, we will use the text validation types that were created in Chapter 3, Extensions. In this example, a function will be created that will determine which text validation type to use based on the parameters passed into the factory method by the code that called it. As a refresher, the code for the TextValidation protocol and the TextValidation protocol extension are shown in the following code:
protocol TextValidation { var regExFindMatchString: String {get} var validationMessage: String {get} } extension TextValidation { var regExMatchingString: String { get { return regExFindMatchString + "$" } } func validateString(str: String) -> Bool { if let _ ...