Imagine that you had an address book class, and you want to be able toprovide a search function. You might provide a simple search function, taking astring and returning all addresses that match the string. Sometimes that's whatusers of the class will want. But what if they want to search only in thedomain name or, more likely, only in the username and ignore results in thedomain name? Or maybe they want to search for all email addresses that alsoshow up in another list. There are a lot of potentially interesting things tosearch for. Instead of building all of these options into the class, wouldn'tit be nice to provide a generic "find" method that takes a procedure fordeciding if an email address is interesting? Let's call the methodfindMatchingAddresses, and have it take a "function" or "function-like" object.
#includeView the Original article
Нема коментара:
Постави коментар