Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GBurgardt/bd46edf38cb6562e45be64c3498550c9 to your computer and use it in GitHub Desktop.
Save GBurgardt/bd46edf38cb6562e45be64c3498550c9 to your computer and use it in GitHub Desktop.
Exercise 2
Is the following code easily maintainable? How would you improve it?
public class Product
{
...
public decimal Price()
{
if (UOM.Equals("grams"))
return Quantity * 6m / 1000;
if (UOM.Equals("bottle"))
return Quantity * 3m;
if (UOM.Equals("bag"))
{
var total += Quantity * .2m;
Página 2/3
var setsOfFour = Quantity / 4;
total -= setsOfFour * .15m; //discount on groups of 4 items
return total;
}
return 0m;
}
}
Exercise 3
How would you improve the maintainability of the following code?
public class Employee
{
private int _type;
static final int ENGINEER = 0;
static final int SALESMAN = 1;
static final int MANAGER = 2;
public double MonthlySalary {get; set;}
public double Commission {get; set;}
public double Bonus {get; set;}
public Employee (int type) { _type = type; }
public int GetPaymentAmount()
{
switch (_type) {
default:
case 0:
return MonthlySalary;
case 1:
return MonthlySalary + Commission;
case 2:
return MonthlySalary + Bonus;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment