Skip to content

Conversation

@crazymagi
Copy link

No description provided.

@crazymagi
Copy link
Author

There are some issues with the code of this PR.

  1. We should put the classes/interfaces into their specific folders. For example: Shape, Square, Circle and Triangle classes could move into "Models" folder. It will help the project more readable.
  2. Too much logic are sit in the main Program.cs. We should use abstract and dependency injection to move the logic out. Similar approach could be apply to other classes as well.
  3. Unit test is missing.
  4. There are quite a lot of styling issues. I recommend to use ReSharper to help with styling.

}

// Order Circle Input
public static Circle OrderCirclesInput()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrderCirclesInput, OrderSquaresInput and OrderTrianglesInput are quite similar, we could abstract it to a generic method. example T OrderShapesInput<T>() where T: Shape.
Another suggestion is moving this logic to a separate factory class. It will help us to separate the logic out and make it testable.

// Order Circle Input
public static Circle OrderCirclesInput()
{
Console.Write("\nPlease input the number of Red Circle: ");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console.Write is a static class, which means hard to test. We could create a ConsoleUserInterface class that implements the IUserInterface interface and wraps a call to the Console.Write method inside an instance method called Write.

public static Circle OrderCirclesInput()
{
Console.Write("\nPlease input the number of Red Circle: ");
int redCircle = Convert.ToInt32(userInput());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static string userInput()
{
string input = Console.ReadLine();
while (string.IsNullOrEmpty(input))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string which contains whitespace only should be invalid as well. Therefore, we should use string.IsNullOrWhiteSpace here.


namespace Order.Management
{
abstract class Shape
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is missing public or internal

public Square(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares)
{
Name = "Square";
base.Price = SquarePrice;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base is redundant in Square, Circle and Triangle classes

return (base.NumberOfYellowShape * Price);
}
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the difference between Square, Circle, and Triangle is Name, Price, and additional charge only. Therefore, we could use Shape abstract base class with properties NumberOfRedShape, NumberOfYellowShape, NumberOfBlueShape and function Total. The properties Name, Price, and AdditionalCharge could be defined as abstract. Also all shapes set the color shape numbers in the constructor. Therefore we could implement it in the base constructor

public class Shape {
    public Shape(int numberOfRedSquares, int numberOfBlueSquares, int numberOfYellowSquares)
    {
            NumberOfRedShape = numberOfRedSquares;
            NumberOfBlueShape = numberOfBlueSquares;
            NumberOfYellowShape = numberOfYellowSquares;
   }
   public int NumberOfRedShape {get; }
   ...

   public int Total() {
       return RedSquaresTotal() + BlueSquaresTotal() + YellowSquaresTotal();
    }

    private int RedSquaresTotal()
    {
        return (NumberOfRedShape * Price);
     }
     private int BlueSquaresTotal()
    {
         return (NumberOfBlueShape * Price);
     }
     private int YellowSquaresTotal()
     {
          return (NumberOfYellowShape * Price);
     }

     public abstract string Name {get; }
     ...

}

public int OrderNumber { get; set; }
public List<Shape> OrderedBlocks { get; set; }

public abstract void GenerateReport();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PaintingReport, CuttingListReport, or InvoiceReport are not different types of Orders. Instead, they are different types of Report services that could generate different reports from the Order. Therefore, we should move the GenerateReport method to an IReportService interface. PaintingReport, CuttingListReport, or InvoiceReport should be the derived class which implement the IReportService interface.

generateTable();
}

public void generateTable()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generateTable method could be private. And for keeping the consistency, we should use pascal case naming, which is GenerateTable

PrintLine();
PrintRow(" ", " Red ", " Blue ", " Yellow ");
PrintLine();
PrintRow("Square", base.OrderedBlocks[0].NumberOfRedShape.ToString(), base.OrderedBlocks[0].NumberOfBlueShape.ToString(), base.OrderedBlocks[0].NumberOfYellowShape.ToString());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All OrderedBlocks are the same structure, which is built by Square, Triangle, and Circle. So we could use a strong type for OrderedBlocks, such as

internal class OrderedBlocks
        {
            public Square Square { get; set; }
            public Triangle Triangle { get; set; }
            public Circle Circle { get; set; }
        }

It will make the code more readable and not error-prone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants