Class and Methods access

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a class and method as follows:

public class ErrorService {
Error GetError(errorId) { ... }
void Mapping() { ... }
}

I would like the Mapping mathod to be "invisible" to other classes.
And the GetError method to be "visible" to other classes and able to
access it as follows:

Error myError = ErrorService.GetError(1);

Without creating an instance of "ErrorService".

What is the correct way to do this? Using static in GetError and keep
Mapping as it is?
And should I also add public to GetError and private to Mapping?

Thanks,
Miguel
 
shapper said:
Hello,

I have a class and method as follows:

public class ErrorService {
Error GetError(errorId) { ... }
void Mapping() { ... }
}

I would like the Mapping mathod to be "invisible" to other classes.
And the GetError method to be "visible" to other classes and able to
access it as follows:

Error myError = ErrorService.GetError(1);

Without creating an instance of "ErrorService".

What is the correct way to do this? Using static in GetError and keep
Mapping as it is?
And should I also add public to GetError and private to Mapping?

public class ErrorService {
public static Error GetError(errorId) { ... }
private static void Mapping() { ... }
}

Note if you never intend for ErrorService to be instanced then you should
also add a static qualifier to the class declaration as well.
 
Back
Top