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

Code repetition in food classes #214

Closed
JoeyChenSmart opened this issue Nov 1, 2020 · 0 comments · Fixed by #218
Closed

Code repetition in food classes #214

JoeyChenSmart opened this issue Nov 1, 2020 · 0 comments · Fixed by #218
Assignees
Labels
code quality improvements for the marks priority.Low This feature/addition is unlikely to be implemented
Milestone

Comments

@JoeyChenSmart
Copy link

All food classes have 2 constructors, e.g.

    public Carbohydrate(int amount) throws IllegalValueException {
        super(amount, CARBOHYDRATE_MULTIPLIER);
    }

    public Carbohydrate(String amount) throws IllegalValueException {
        this(Integer.parseInt(amount));
    }

This violates SRP since our food item is now doing parsing. Also DRY since this parsing is repeated in every class.

Note that the second constructor is only used in tests. Creation of this object during runtime will always be through a parser that uses the first constructor. We should remove the second constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality improvements for the marks priority.Low This feature/addition is unlikely to be implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants