Extract Password Validation into Its Own Type

Moving up the view controller helper methods, the next ones are updateViewModelToTextFields and validateInputs. They involve the view model’s validation of the inputs to the password fields. Let’s find a way to move that validation out of the view model.

The view model has methods that check the password inputs against business rules. Rather than moving these into the presenter, it would make sense to extract them into their own type. Let’s apply the Extract Class refactoring, which has the following mechanics:

  • Decide how to split the responsibilities of the class.

What we’d like to end up with is a value type that takes the three password inputs and answers questions about their validity. ...

Get iOS Unit Testing by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.