What would you call the "helper method"?

I am wondering which methods are "helper methods". Where should we draw the border of the tag to say that a particular method is a "helper method"? In fact, I consider any method as a "helper method", if it is not an initialization method, a method implemented to match the protocol response or delegation method. Any other method that I implement to accomplish something is a “helper method” in my perspective, but I feel that there are more categories to think about.

Why do I want to know this? Because I want to use the use of the #pragma HEADLINE icon in Xcode. I find it nice to organize the code in some way.

Please help me get my photo of the "helper method". Examples are appreciated!

+3
source share
7 answers

I see this as methods that are not required for the library to function properly, but make things more convenient or readable to the end user.

Hmmm ... did not give an example. Let's say you have a function to get users from a database, and it took the form

User GetUsers(UserRole)
{
//Do Something
}

And an example of a helper method might be

User GetAdmins()
{
   return GetUsers("Admins");
}

His example is crude pseudo-codes, but gives you the gist. GetAdmins functionality is completed in GetUsers (), but the GetAdmins helper function helps readability (and nothing more).

Make sense?

+3
source

, , , , . .

+1

, . , , , .

+1

, . , , . , , .

+1

, , , , , .

:

  • +[NSObject new] [[NSObject alloc] init];
  • NSClassFromString(str) objc_getClass([str UTF8String]);
  • +[NSURL URLWithString:str] [[[NSURL alloc] initWithString:str] autorelease];
  • -[NSURLRequest initWithRequest:request delegate:delegate] [request initWithRequest:request delegate:delegate startImmediately:NO]
  • -[NSString substringFromIndex:] -[NSString substringWithRange:]
+1

-, , -, . , - NSString, NSDate, , NSDateFormatters .

-, DRY- , -, , API (, , , ).

, , Extensions , , " " Objective-C. : +(NSError *)errorWithCFStreamError:(CFStreamError)streamError, " " CFStreamError NSError/CFErrorRef , OS X 10.5 ( iPhone).

+1

In Objective-C, I think you could call any private method a "helper method", where in particular I mean that the signature of the method does not appear in the .h file. That is, these are the methods that you probably declare in the continuation of the class in the .m file:

@interface MyClass ()
- (void)somePrivateMethod;
@end

Some other answers call helper methods — optional, but generally available methods that are not critical to the API — I would rather call convenience methods.

+1
source

Source: https://habr.com/ru/post/1708292/


All Articles