code_junkie

do you put your calculations on your sets or your gets .

Nov 13th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. public class Order
  2. {
  3. private double _price;
  4. private double _quantity;
  5.  
  6. public double TotalCash
  7. {
  8. get
  9. {
  10. return _price * _quantity;
  11. }
  12. }
  13.  
  14. public class Order
  15. {
  16.  
  17. private double _totalCash;
  18. private double _price;
  19. private double _quantity;
  20.  
  21. private void CalcCashTotal()
  22. {
  23. _totalCash = _price * _quantity
  24. }
  25.  
  26. public double Price
  27. {
  28. set
  29. {
  30. _price = value;
  31. CalcCashTotal();
  32. }
  33. }
  34.  
  35. public double Quantity
  36. {
  37. set
  38. {
  39. _price = value;
  40. CalcCashTotal();
  41. }
  42. }
  43.  
  44.  
  45. public double TotalCash
  46. {
  47. get
  48. {
  49. return _totalCash;
  50. }
  51. }
  52.  
  53. public class Order
  54. {
  55. private double _totalCash;
  56. private double _price;
  57. private double _quantity;
  58. private _IsDirtyTotalCash = true;
  59.  
  60. private void CalcCashTotal()
  61. {
  62. _totalCash = _price * _quantity
  63. }
  64.  
  65. public double Price
  66. {
  67. set
  68. {
  69. _price = value;
  70. _IsDirtyTotalCash = true;
  71. }
  72. }
  73.  
  74. public double Quantity
  75. {
  76. set
  77. {
  78. _price = value;
  79. _IsDirtyTotalCash = true;
  80. }
  81. }
  82.  
  83. public double TotalCash
  84. {
  85. get
  86. {
  87. if(_IsDirtyTotalCash)
  88. {
  89. _totalCash = CalcTotalCost();
  90. _isDirtyTotalCash = false;
  91. }
  92. return _totalCash;
  93. }
  94. }
  95.  
  96. }
  97.  
  98. double subTotal = myOrder.TotalCash;
  99. double tax = subTotal * 0.05;
  100. double shipping = subTotal > 100 ? 0 : 5.95;
  101. double grandTotal = subTotal + tax + shipping;
  102. OutputToUser(subTotal, tax, shipping, grandTotal);
  103.  
  104. double tax = myOrder.TotalCash * 0.05;
  105. double shipping = myOrder.TotalCash > 100 ? 0 : 5.95;
  106. double grandTotal = myOrder.TotalCash + tax + shipping;
  107. OutputToUser(myOrder.TotalCash, tax, shipping, grandTotal);
  108.  
  109. class Wall {
  110. public decimal Width {
  111. get {
  112. ...
  113. }
  114. set {
  115. ValidateChanges();
  116. width = value;
  117. CreateBays();
  118. }
  119. }
  120.  
  121. public Bays[] Bays {
  122. get {
  123. ...
  124. }
  125. set {
  126. ValidateChanges();
  127. ...
  128. }
  129. }
  130.  
  131. private void CreateBays() {
  132. // Delete all the old bays.
  133. ...
  134. // Create a new bay per spacing interval given the wall width.
  135. ...
  136. }
  137. }
Add Comment
Please, Sign In to add comment