Chapter 19. Strategy
Do you remember the last time you stuffed a bunch of different algorithms in the same block of code and used spaghetti of if-else
/ switch-case
conditional statements to determine which one to use? The algorithms could be a bunch of functions/methods of similar classes that solve related problems. For example, I have a routine that validates some input data. The data itself can be of any data type (e.g., CGFloat
, NSString
, NSInteger
, etc.). Each of the data types requires a different validation algorithm. If we can encapsulate each algorithm as an object, then we can eliminate a bunch of if-else
/ switch-case
statements for data type checking in order to determine what algorithm to use.
In object-oriented software design, we ...
Get Pro Objective-C Design Patterns for iOS 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.