Skip to content
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

Implemented the FruitShop using Solid principles #959

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dima-semeniuk
Copy link

No description provided.

Copy link

@RostyslavKuzmych RostyslavKuzmych left a comment

Choose a reason for hiding this comment

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

Good job!

Copy link

@kshuryhin kshuryhin left a comment

Choose a reason for hiding this comment

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

Good job, but there some points to consider as well

public class ReportCreatorImpl implements ReportCreator {
private static final String SEPARATOR = ",";
private static final String REPORT_HEADER = "fruit,quantity";
private final StorageDao storageDao = new StorageDaoImpl();

Choose a reason for hiding this comment

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

Consider injecting storage dao implementation through the constructor.

return storageDao.getALl().entrySet().stream()
.map(e -> e.getKey().getName() + SEPARATOR + e.getValue())
.collect(Collectors.joining(System.lineSeparator(),
REPORT_HEADER + System.lineSeparator(), ""));

Choose a reason for hiding this comment

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

Just for the consistency, make "" a constant as well

Comment on lines 14 to 17
private DataReader dataReader;
private DataProcessing dataProcessing;
private ReportCreator reportCreator;
private Writer writer;

Choose a reason for hiding this comment

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

Consider making them final

Comment on lines 20 to 23
dataReader = new DataReaderFromCsv();
dataProcessing = new DataProcessingImpl(new OperationStrategyImpl(map));
reportCreator = new ReportCreatorImpl();
writer = new CsvWriter();

Choose a reason for hiding this comment

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

I would say it is preferable to pass the initialisation objects to the constructor, like
public FruitServiceImpl(DataReader dataReader,...)

private static final int OPERATION_POSITION = 0;
private static final int FRUIT_NAME_POSITION = 1;
private static final int AMOUNT_OF_FRUIT_POSITION = 2;
private OperationStrategy operationStrategy;

Choose a reason for hiding this comment

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

Could be final I guess


@Override
public void updateStorage(FruitTransaction transaction) {
if (transaction.getAmount() < MIN_AMOUNT) {

Choose a reason for hiding this comment

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

It looks like you are doing this check in several places. Probably we can extract it to some helper utility method?


public class SupplyOperationHandler implements OperationHandler {
private static final int MIN_AMOUNT = 0;
private StorageDao storageDao = new StorageDaoImpl();

Choose a reason for hiding this comment

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

May be final and consider initialising through the constructor as well

}
}

private boolean validAmountOfFruit(FruitTransaction transaction) {

Choose a reason for hiding this comment

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

Probably there is no need in boolean return value. We can simply make it void and just call it in updateStorage

private String fruitName;
private int amount;

public Operation getOperationByLetter(String letter) {

Choose a reason for hiding this comment

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

Just wondering if it is correct to make Operation in the same file as FruitTransaction? I see it is used not only inside enclosing class, so probable we can extract Operation to the separate file?

Copy link

@kshuryhin kshuryhin left a comment

Choose a reason for hiding this comment

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

LGTM, just some minor stuff to polish

import java.util.List;

public class DataReaderFromCsv implements DataReader {
private static final int rowToSkip = 1;

Choose a reason for hiding this comment

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

Pay more attention to the constants format in Java

import core.basesyntax.model.FruitTransaction;

public interface OperationHandler {
int MIN_AMOUNT = 0;

Choose a reason for hiding this comment

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

Probably we can make it protected or private here?

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.

3 participants