-
Notifications
You must be signed in to change notification settings - Fork 45
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
Pipes - Sara Frandsen - Hotel #46
base: master
Are you sure you want to change the base?
Conversation
HotelWhat We're Looking For
This is a good start, but I feel that there's a way to go yet. It seems to me that your design choice to use class variables and methods on That being said, the specific method code you wrote is very clean and readable, and struggling against and learning from tough design choices was part of the goal of this project. Keep up the hard work, and if you want to sit down and talk about different ways of structuring things let one of us know. |
lib/date_range.rb
Outdated
def initialize(check_in, check_out) | ||
@check_in = check_in | ||
@check_out = check_out | ||
end # end initialize |
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 would be a great place to include a check that the date range is valid.
lib/reservation.rb
Outdated
module Hotel | ||
class Reservation # various ways to list reservations | ||
COST = 200 # per night | ||
@@reservations = [] # list of all reservations made |
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.
Using a class variable on Reservation
to store the list of reservations is an interesting idea, and matches pretty closely what we did on Grocery Store. However, I think that in this case it ends up making the design more complicated.
The reason is that the Reservation
class now has two responsibilities:
- Instances of
Reservation
must keep track of the details of an individual reservation - The
Reservation
class itself must do all the work of keeping track of the list.
Having these two responsibilities tied together like this makes the code inflexible and difficult to extend, as you discovered when you began work on Wave 3.
It also makes it more difficult to test, because there's no easy way to reset all the state of a class.
An alternative approach would be to create another class, something like Hotel
, that keeps track of all the rooms, reservations and blocks.
lib/reservation.rb
Outdated
@guest_name = guest_name | ||
@check_in = check_in | ||
@check_out = check_out | ||
@dates = Hotel::DateRange.new(check_in, check_out) |
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 you're saving the check_in
and check_out
in @dates
, you should not also be saving them as instance variables.
lib/reservation.rb
Outdated
def self.available_rooms(date_range) # list reservations on given date range | ||
reservations_in_range = @@reservations.reject do |reservation| # excludes reservastions outside date range | ||
reservation.check_out < date_range.check_in || reservation.check_in > date_range.check_out | ||
end |
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.
I would argue that this bit of logic to check whether a reservation conflicts with a date range is just complex enough to warrant its own method. In fact, I think it would make sense to remove it from this method entirely, and instead write an instance method DateRange#overlap?(other)
, which takes another date range and returns the result of this check.
That would be a clean separation of responsibilities between Reservation
and DateRange
, making DateRange
easier to reuse for something like a block of rooms, and it would also make this logic easier to test.
specs/reservation_spec.rb
Outdated
describe 'self.on_date' do | ||
it 'returns a list of reservations for a specific date' do | ||
Hotel::Reservation.on_date(Date.new(2018, 1, 17)).must_equal [kitten_expo] | ||
end # end test |
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.
Other cases I'd be interested in:
- What if there are no reservations? (it should return an empty list)
- Do reservations that don't overlap the date range affect the list? (they shouldn't)
- Check the boundaries of what counts as an overlap. What about a reservation that ends on the checkin date, or starts on the checkout date?
- What if your date range spans several small reservations? (all of those reservations should be in the list)
specs/reservation_spec.rb
Outdated
describe 'self.available_rooms' do | ||
it 'excludes reservations outside a given date range' do | ||
given_range = Hotel::DateRange.new(Date.new(2017, 01, 01), Date.new(2017, 12, 31)) | ||
|
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 a good start, but I'd like to see more coverage around what rooms are considered available. Cases I'd be interested in:
- Not available:
- Same dates
- Overlaps in the front
- Overlaps in the back
- Completely contained
- Completely containing
- Available:
- Completely before
- Completely after
- Ends on the checkin date
- Starts on the checkout date
…ec tests for overlap
Hotel
Congratulations! You're submitting your assignment!
Comprehension Questions