code_junkie

How do I hide a method so it's not called by programmers but still usable in code?

Nov 12th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. public class Ship
  2.  
  3. public bool Validate()
  4. {
  5. //validate properties only found on a ship
  6.  
  7. FurtherValidate();
  8. }
  9.  
  10. public abstract bool FurtherValidate();
  11.  
  12. public override bool FurtherValidate()
  13. {
  14. //validate properties only found on a lifeboat
  15. }
  16.  
  17. public class Ship
  18. {
  19. public virtual bool Validate()
  20. {
  21. //validate properties only found on a ship
  22. return true;
  23. }
  24. }
  25. public class Lifeboat : Ship
  26. {
  27. public override bool Validate()
  28. {
  29. base.Validate();
  30. // lifeboat specific code
  31. return true;
  32. }
  33. }
  34.  
  35. protected abstract bool FurtherValidate();
  36.  
  37. protected IValidator FurtherValidation { private get; set; }
  38.  
  39. public bool Validate()
  40. {
  41. //validate properties only found on a ship
  42.  
  43. if (FurtherValidation == null)
  44. throw new ValidationIsRequiredException();
  45. if (!FurtherValidation.IsValid(this))
  46. // logic for invalid state
  47. }
Add Comment
Please, Sign In to add comment