-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
done #1750
base: master
Are you sure you want to change the base?
done #1750
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on implementing the AreaCalculator
and Draw
interfaces, as well as the various figure classes! 🎉 Your code structure is well-organized, and you've effectively utilized interfaces and enums to ensure consistency across implementations. Here are a few key points to consider for improvement:
-
Magic Numbers: Replace magic numbers with named constants to enhance code readability and maintainability. This will make your code easier to understand and modify in the future.
-
FigureSupplier Instance: Create a single instance of
FigureSupplier
outside the loop in theMain
class to avoid unnecessary instantiation. This will improve performance and readability. -
Random Figure Generation: Recalculate the
index
inside thegetRandomFigure
method to ensure a different figure type can be returned each time, providing more variety in generated figures. -
Abstract Methods: Consider making the
calculateArea
anddraw
methods abstract in theFigure
class to enforce that subclasses provide meaningful implementations. -
Color Consistency: Return a
Color
type instead of aString
from thegetRandomColor
method to maintain type consistency across your application.
These improvements will help you write cleaner, more efficient code. Keep up the great work, and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
public String getRandomColor() { | ||
Color[] color = Color.values(); | ||
return color[random.nextInt(color.length)].name(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider returning a Color
type instead of a String
from the getRandomColor
method. This will ensure type consistency across the application when dealing with colors.
public double calculateArea() { | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The calculateArea
method returns 0, which might not be meaningful for a base class. Consider making this method abstract to enforce subclasses to provide their own implementation.
public void draw() { | ||
System.out.println("message"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The draw
method currently prints a generic message. Consider making this method abstract or providing a more meaningful default implementation.
private int maxBound = 5; | ||
private ColorSupplier colorSupplier = new ColorSupplier(); | ||
private Random random = new Random(); | ||
private int index = random.nextInt(maxBound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The index
is calculated once during the instantiation of FigureSupplier
. This means getRandomFigure
will always return the same type of figure. Consider recalculating index
inside the getRandomFigure
method to ensure a different figure type can be returned each time.
private int defaultSize = 10; | ||
private int maxSize = 50; | ||
private int maxBound = 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using magic numbers directly in the code. Define defaultSize
, maxSize
, maxBound
, and any other magic numbers as constants to improve code readability and maintainability.
return new Circle(randomSize(), colorSupplier.getRandomColor()); | ||
case 1: | ||
return new Square(randomSize(), colorSupplier.getRandomColor()); | ||
case 2: | ||
return new Rectangle(colorSupplier.getRandomColor(), randomSize(), randomSize()); | ||
case 3: | ||
return new RightTriangle(randomSize(), | ||
randomSize(), colorSupplier.getRandomColor()); | ||
default: | ||
return new IsoscelesTrapezoid(randomSize(), | ||
randomSize(), randomSize(), colorSupplier.getRandomColor()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When creating figures, avoid passing expressions directly into constructors. Instead, assign the results of expressions to variables and pass those variables to constructors. This improves code readability.
figures[i] = new FigureSupplier().getRandomFigure(); | ||
figures[i].draw(); | ||
} else { | ||
figures[i] = new FigureSupplier().getDefaultFigure(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider creating a single instance of FigureSupplier
outside the loop to avoid unnecessary instantiation within each iteration. This will improve performance and readability.
@Override | ||
public void draw() { | ||
String firstPart = "Figure: square, area: " + calculateArea() + " sq. units, side: "; | ||
String secondPart = side + " unists, color: " + getColor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the word 'unists'. It should be 'units'.
No description provided.