Created
August 16, 2019 21:20
-
-
Save ClysmiC/286d49670139df4e50494e4d2d4730e7 to your computer and use it in GitHub Desktop.
Access modifier on optional parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SecureTransactor | |
{ | |
public bool DoManySecureTransactions(string[] data) | |
{ | |
if (!SecurityCheck()) return false; | |
bool doCheck = false; // We already did the check, no need to repeat ourselves! | |
foreach(string datum in data) | |
{ | |
DoSecureTranaction(data, doCheck); | |
} | |
} | |
public bool DoSecureTransaction(string data, protected bool doSecurityCheck=true) | |
{ | |
// Notice the protected default argument. Externally, this function can only be | |
// called with 1 argument. Internally, we can supply whatever value we choose | |
if (doSecurityChecks && !SecurityCheck()) | |
{ | |
return false; | |
} | |
// ... | |
return true; | |
} | |
protected bool SecurityCheck() | |
{ | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment