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

Solid Principles compliance #4

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

Conversation

dsantistevan
Copy link

@dsantistevan dsantistevan commented Jul 13, 2020

#3 The class Guest that has the variables held before by a room has been added to the project, also some changes were made to the Project.java class in order to comply with it. The class Guest has the following structure:

public class Guest implements Serializable{
	String name;
    String contact;
    String gender;

The attributes kept default access so the program can access them like before.

#5 The fixes to the OCP principle were made by creating an abstract class Room that has an ArrayList of Guest objects and can add up to maxCapacity int variable amount of elements. SingleRoom has a maxCapacity of 1 and DoubleRoom a max capacity of 2. Also, the code was adjusted to comply with these changes.
The class Room has the following structure and method addGuest():

abstract class Room implements Serializable{
	ArrayList<Guest> guests=new ArrayList<>();
	int maxCapacity;
	ArrayList<Food> food =new ArrayList<>();
	
	void addGuest(Guest g) {
		if(g!=null && guests.size()<maxCapacity)
			guests.add(g);
		else if(g!=null)
			throw new NotAvailable();
		
	}
}

@dsantistevan
Copy link
Author

dsantistevan commented Jul 13, 2020

#6 Added classes FoodItem and FoodList, in order to comply with Open Closed Principle of SOLID design.
Now to extend the amount of items it's just needed to add them at the initiateFood method, it could also read from a file, but now it is only necessary to modify initiateFood.

        static void initiateFood() {
		foodList.add(new FoodItem(50,1));
		foodList.add(new FoodItem(60,2));
		foodList.add(new FoodItem(70,3));
		foodList.add(new FoodItem(30,4));
	}

@dsantistevan dsantistevan changed the title Added Guest class and adjusted code to comply with it Solid Principles compliance Jul 13, 2020
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.

None yet

1 participant