patterncsharpModerate
Interview task - SOLID Principle and TDD
Viewed 0 times
principleinterviewandsolidtddtask
Problem
I had a small technical C# task using SOLID principle and TDD. But I failed to prove my coding skill through the test.
Can anyone offer any small advice for me? I am really eager to learn what my faults are and how I can improve.
The interview question is here, and my answer is here.
I just reference here some pieces of my source code.
Program.cs
Calculator Classes
```
interface ITaxCalculatorFactory
{
ITaxCalculator GetObject(decimal taxRate);
ITaxCalculator GetObject(ITaxRepository taxRepo);
}
public class TaxCalculatorFactory
{
public TaxCalculatorFactory()
{
}
public ITaxCalculator GetObject(decimal dAmount)
{
return
Can anyone offer any small advice for me? I am really eager to learn what my faults are and how I can improve.
The interview question is here, and my answer is here.
I just reference here some pieces of my source code.
Program.cs
class Program
{
static void Main(string[] args)
{
////////////////////////////////////////////////////////////////////////////////
// Story 1. As a donor
Console.WriteLine("-------------------------------------- Story1\r\n");
//1.1. Craete Tax Calculator
decimal taxRate = 20;
ITaxCalculator taxCalculator = new TaxCalculator(taxRate);
//1.2. Display GiftAid
Console.WriteLine("Please enter donation amount:");
decimal Amount = decimal.Parse(Console.ReadLine());
Console.WriteLine("=> Your Gift Aid is: {0} \r\n\r\n", taxCalculator.GetGiftAid(Amount));
////////////////////////////////////////////////////////////////////////////////
// Story 2. As a site administrator
Console.WriteLine("-------------------------------------- Story2\r\n");
//2.1. Create using factory pattern
taxCalculator = new TaxCalculatorFactory().GetObject(new TaxRepository());
Console.WriteLine("Please enter donation amount:");
Amount = decimal.Parse(Console.ReadLine());
//2.2. Display GiftAid
Console.WriteLine("=> Your Gift Aid is: {0} \r\n\r\n", taxCalculator.GetGiftAid(Amount));
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
}Calculator Classes
```
interface ITaxCalculatorFactory
{
ITaxCalculator GetObject(decimal taxRate);
ITaxCalculator GetObject(ITaxRepository taxRepo);
}
public class TaxCalculatorFactory
{
public TaxCalculatorFactory()
{
}
public ITaxCalculator GetObject(decimal dAmount)
{
return
Solution
-
The interview defines 4 user stories but you have only really implemented 2 as far as I can see.
-
Story 3 says that the amount should be rounded to 2 decimal places. You have done that by applying the rounding to the result as part of a unit test which misses the point of the story (imho). The story says something about "should be displayed rounded to two decimal places" so it might need a tax calculator view which displays the results as per requirements.
-
You should avoid having two ways of creating your
-
-
I would prefer
-
Remove the
The interview defines 4 user stories but you have only really implemented 2 as far as I can see.
-
Story 3 says that the amount should be rounded to 2 decimal places. You have done that by applying the rounding to the result as part of a unit test which misses the point of the story (imho). The story says something about "should be displayed rounded to two decimal places" so it might need a tax calculator view which displays the results as per requirements.
-
You should avoid having two ways of creating your
TaxCalculator objects. If you have a factory then you usually don't want the user to instantiate new objects by new. If I were to use your class I would not know which way to use and if there is a difference or not.-
dAmount smells like hungarian notation of which I'm not a fan of and which is generally frowned upon.-
I would prefer
Create over GetObject as method name in the factory. -
Remove the
GetObject(decimal amount) factory method - you can pass a mock repository in unit tests which always returns a fixed amount.Context
StackExchange Code Review Q#41834, answer score: 16
Revisions (0)
No revisions yet.