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

More robust version for beverage-machine & Proper distribution of matches for IPL-tournament #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kathanLunagariya
Copy link

the PR consists...

  • removed code redundancy for all beverage classes...only a single function to handle all the stuff.
  • Round robin match scheduling to schedule matches among teams.

Copy link
Contributor

@vimal-parakhiya vimal-parakhiya left a comment

Choose a reason for hiding this comment

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

Added feedbacks to further improvize the code.

@@ -28,5 +32,11 @@ public void validateBeveragesAreAvailable(){
}
}

public String configBeverage(BeverageType type){
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically this is correct solution!
It also meets the constrainsts that we've laid out in the workshop.
So, good effort on this.

However, there is scope to improvize it further, i.e.

  1. As a good design practice, we should follow Single Responsibility principle (as much as we can). Here base class holds all the messages and so in a way, base class knows about different beverage types, which are supported. As per Single Responsibility Principle, we should avoid this.
  2. While adding support for new beverage, we need to implement new class as well as we need to modify the BeverageMaker as well (though just a tiny change about adding new message in the config array). Ideally, while adding support for new Beverage type, there should not be a need to modify BeverageMaker (base) class.

So, let's improvize it further so that the

  1. Beverage message (prepration logic) is inside child classes only, i.e. BeverageMaker will not store these messages.
  2. While adding support for new beverage type, we do not need to modify BeverageMaker as base class.

Hint:
Implementation as of yesterday,

class MochaMaker extens BeverageMaker {
  public String dispenseBeverage() {
        validateBeveragesAreAvailable();
        updateBeverageCount();
        return "Enjoy your cup of Mocha made from exotic chocolate!";
    }
}

Is it possible to modify it like below? Find a pattern and then apply the learnings from yesterday's session to eliminate duplicate code across all BeverageMakers?

class MochaMaker extens BeverageMaker {
  public String dispenseBeverage() {
        validateBeveragesAreAvailable();
        updateBeverageCount();
        return prepareBeverage();
    }
    
   public String prepareBeverage() {
      return "Enjoy your cup of Mocha made from exotic chocolate!";
   }
}

int j = teams.size()-1;

if (teams.size() % 2 == 0) {
while (r < teams.size() - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to be a correct approach.

However, in each round, we also need to schedule a match between last team in the array and team at array position (n-1)/2, where n is the total team count.

That is the team which is located at top in the polygon and the one at the center.
You may want to refer below link,
https://nrich.maths.org/1443

For example, if team size is 10 (Team-0 to Team-9), the scheduled matches in first round would be,

  • Team 0 - Team 8
  • Team 1 - Team 7
  • Team 2 - Team 6
  • Team 3 - Team 5
  • Team 4 - Team 9 (Team at top of the polygon vs Team at the centre of polygon)

Additionally, using above reference link, also try to implement it for odd number of teams.

At last, try to schedule matches (when team count is >= 10) so that none of the team has to play matches on consecutive days, i.e. each team will get at least one day to rest/practice after playing a match.

j = teams.size() - 1;

//right shifting of teams...
List<Team> temp = new ArrayList<>(teams);
Copy link
Contributor

Choose a reason for hiding this comment

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

We can further simplify the array rotation, using the methods supported by List/ArrayList. This will eliminate the for loop completely.

You may want to look at below documentation and see, which methods could be used to achieve this.
https://docs.oracle.com/javase/8/docs/api/java/util/List.html

@vimal-parakhiya
Copy link
Contributor

@kathanLunagariya just curious, if you got a chance to look at above review comments and improvize it further?

@kathanLunagariya
Copy link
Author

@kathanLunagariya just curious, if you got a chance to look at above review comments and improvize it further?

Thanks for reaching out to me...
Yes, I had seen the comments and also went through the mentioned resources but haven't made any changes yet.

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