Sorry if the question sounds confusing. What I mean is that if I have a class that has a method that does a bunch of calculations and then returns a value, I can either make that method public (which gives my other classes access), or I can make it private and make a public get method.
Something like this:
public publicmethod{
return privatemethod();
}
private privatemethod{
//do stuff
return value;
}
Is this a futile exercise or does it provide additional program security?
Well, there is no additional security here. However, such a usage can sometimes make sense.
For example, the private and public method may have different semantics.
So your implementation is just calling to a private method — but what is important, you expose the semantics: your
BuyFoodoperation is justBuyChopSuey(). Your code says: “in this class, buying food is just buying chop suey” in a clear way. You are able to addBuyTsingtaoBeer()intoBuyFood()any time without changing the semantics of the both methods.