-
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
Created an example of a figure factory #1330
base: master
Are you sure you want to change the base?
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.
Before you create PR with your homework, you need to go through the checklist under the task and correct all the points described there
package core.basesyntax; | ||
|
||
public class Circle extends Figure { | ||
private double radius = 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.
private double radius = 0; | |
private double radius; |
Circle() { | ||
super("circle", Color.WHITE); | ||
} |
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.
this is unexpected
super("circle", Color.WHITE); | ||
} | ||
|
||
Circle(Color color) { |
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.
public
if (radius > 0) { | ||
this.radius = radius; | ||
} else { | ||
System.out.println("Circle radius can't be negative or equal to zero!"); | ||
} |
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.
if (radius > 0) { | |
this.radius = radius; | |
} else { | |
System.out.println("Circle radius can't be negative or equal to zero!"); | |
} | |
this.radius = radius; |
@@ -0,0 +1,5 @@ | |||
package core.basesyntax; | |||
|
|||
public interface DrawAble { |
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.
public interface DrawAble { | |
public interface Drawable { |
package core.basesyntax; | ||
|
||
public interface AreaCalculator { | ||
double area(); |
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.
double area(); | |
double getArea(); |
public class FigureSupplier { | ||
private final Random random = new Random(); | ||
private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
private final int figureAmount = 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.
|
||
public Figure getDefaultFigure() { | ||
Circle circle = new Circle(); | ||
circle.setRadius(10); |
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.
public class Circle extends Figure { | ||
private double radius; | ||
|
||
public Circle() { |
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.
KISS - if you dont need default constructor - just delete it
Circle circle = new Circle(); | ||
circle.setRadius(DEFAULT_RADIUS); | ||
return circle; |
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.
Circle circle = new Circle(); | |
circle.setRadius(DEFAULT_RADIUS); | |
return circle; | |
return new Circle(DEFAULT_RADIUS); |
|
||
public class FiguresExpo { | ||
public static void main(String[] args) { | ||
Figure[] figures = new Figure[10]; |
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.
extract it to variable
FigureSupplier figureSupplier = new FigureSupplier(); | ||
|
||
for (int i = 0; i < figures.length; i++) { | ||
if (i < 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.
what if we would have only 2 figures? think about how to make this code more universal
} | ||
} | ||
|
||
for (Figure figure: figures) { |
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.
no need to create another loop, can do this in the loop above
…plier class/ create constructor in FigureSupplier for set figures array size
No description provided.