Protecting methods

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Suppose that in the class named the ProductDB.cs I want to protect the
method logic from being accessed from other classes, but I still want to let
other classes to call the method. The protected method is:

private static ArrayList ReadProducts()
{
...all the logic to goes here
}

In order to let other classes to access this method I then create a public
method that just calls the private method, like:

public static ArrayList GetProducts()
{
return ReadProducts();
}
private static ArrayList ReadProducts()
{
...all the logic to goes here
}

Is it a good design for this idea?

Regards,
KenA
 
KenA said:
Suppose that in the class named the ProductDB.cs I want to protect the
method logic from being accessed from other classes, but I still want to
let
other classes to call the method. The protected method is:

private static ArrayList ReadProducts()
{
...all the logic to goes here
}

In order to let other classes to access this method I then create a public
method that just calls the private method, like:

public static ArrayList GetProducts()
{
return ReadProducts();
}
private static ArrayList ReadProducts()
{
...all the logic to goes here
}

Is it a good design for this idea?

It doesn't appear to get you anything at all, so why not just make the other
one public? How exactly is that protecting the method logic? Are you talking
with an obfusticater?
 
Daniel O'Connell said:
It doesn't appear to get you anything at all, so why not just make the other
one public? How exactly is that protecting the method logic? Are you talking
with an obfusticater?

No, not obfuscator. I´m just not sure if doing the private method
ReadProducts() as a public one is the best way to go. Is there a way to let
ReadProducts() method to be available to other classes and in the same time
make it a private method?
 
KenA said:
No, not obfuscator. I´m just not sure if doing the private method
ReadProducts() as a public one is the best way to go. Is there a way to
let
ReadProducts() method to be available to other classes and in the same
time
make it a private method?

Well, why does it need to be private if an external consumer needs access to
it? I'd say just let it be public unless you have a reason not to
(obfustication, public method needs extra processing).
 
That´s probably nonsense ... as you said if an external consumer needs access
to it, then it should be public. Thanks :-)
 
Back
Top