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

Shaunna Wiens --carets #36

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fefe406
set up initial code files, spec files and rakefile
skwiens Sep 5, 2017
d843cbf
initialize room specs and code complete
skwiens Sep 5, 2017
bc40fe8
initialize reservation code and specs complete
skwiens Sep 6, 2017
25c53b0
reader method code and specs for reservation added
skwiens Sep 6, 2017
478e62b
initialize hotel and specs finished'
skwiens Sep 6, 2017
853379b
date_include? code and specs written
skwiens Sep 6, 2017
1a8635b
hotel/spec get_res_by_date code and specs added
skwiens Sep 6, 2017
9bfad5a
created pricing class and spec
skwiens Sep 6, 2017
688ea84
get_available_rooms in hotel class and ability for user to request ro…
skwiens Sep 7, 2017
ba7788f
make list of available room, still bugs on edge cases
skwiens Sep 7, 2017
611a824
wave 2 requirements complete
skwiens Sep 7, 2017
cbbed4c
block file and spec initialize created
skwiens Sep 7, 2017
52bba64
make a block added to hotel file and spec
skwiens Sep 8, 2017
62265bf
make_block method changed and block code changed to add rooms to the …
skwiens Sep 8, 2017
ab8cb65
make reservation from a block update specs to account for requirement…
skwiens Sep 8, 2017
f82db1f
all initial requirements met, now can make reservations from a block …
skwiens Sep 8, 2017
1e4a7a6
adjusted pricing method, tests for unique block id
skwiens Sep 8, 2017
a146729
created CLI ruby file and spec
skwiens Sep 8, 2017
f6b0980
get_room method added to cli
skwiens Sep 9, 2017
6a72a20
cli - change price of room per night
skwiens Sep 10, 2017
e2ccb96
view available rooms in block cli added
skwiens Sep 10, 2017
2cabb58
basic user interface works with multiple bugs
skwiens Sep 10, 2017
aa2fd76
some bugs fixed....
skwiens Sep 10, 2017
bcc9b52
cli file finished, still some bugs, no tests. cli_spec name chagnd so…
skwiens Sep 11, 2017
918005d
design-acitvity included
skwiens Sep 28, 2017
abaadea
updated design_acitivity
skwiens Sep 28, 2017
499175d
added a date_range class
skwiens Sep 29, 2017
a7b858f
description of hotel changes in design-activity
skwiens Sep 29, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
73 changes: 73 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Activity: Evaluating Responsibility

* **What classes does each implementation include? Are the lists the same?**

Each implementation includes the following classes (They are the same):
CartEntry
ShoppingCart
Order


* **Write down a sentence to describe each class.**

CartEntry: This class includes the quantity and price of each item in the ShoppingCart

ShoppingCart: This class includes an array of entries.

Order: This class calculates the total price of the order including sales tax.

_In implementation B the CartEntry calculates the cost of the entry and the ShoppingCart calculated the total (with sales tax being included in the order). In implementation A the Order combines all the calculations for price._


* **How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.**

ShoppingCart holds an array that can be filled with instances of CartEntry (or anything else for that matter, since it isn't hard coded into the ShoppingCart class.) Order has-a ShoppingCart

* **What data does each class store? How (if at all) does this differ between the two implementations?**

CartEntry: unit price and quantity of the item in the cart
ShoppingCart: collection of entries
Order: an instance of ShoppingCart, and the constant value of the SALES_TAX.

The data stored in each class is the same for both classes, the difference is that in implementation A the Order is responsible for all the pricing calculations whereas in Implementation B, each class has a method to communicate the calculation of the price.

* **What methods does each class have? How (if at all) does this differ between the two implementations?**

A:
CartEntry: attr_accessor for unit price and quantity
ShoppingCart: attr_accessor for entries
Order: total_price to calculate the total price of the Order

B:
CartEntry: same as A with additional price method to calculate the price of the CartEntry
ShoppingCart: same as A with an additional price method to calculate the sum of all the CartEntry prices
Order: same, but the total_price method receives a method from the ShoppingCart to receive the total price before tax and the uses that to calculate the total_price with tax. This is a better implementation since the calculation done on the entries is done in their respective methods instead of in the Order class.

* **Consider the Order#total_price method. In each implementation:
Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?**
A: computing the price is all retained in Order
B: delegated to "lower level" classes

* **Does total_price directly manipulate the instance variables of other classes?**
I struggle with this question in terms of what it means to manipulate an instance variable. total_price does not change the value of any of the instance variables from other classes, but it does make calculations using the instance variables.

* **If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?**

We would need to write a conditional statement into the price. This would be easier to modify in implementation B.

* **Which implementation better adheres to the single responsibility principle?**

Implementation B better adheres to the single responsibility principle.

* **Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?**

Implementation B is more loosely coupled.
-------------------

# Revisiting Hotel Activity:

A change that I decided to make to my Hotel project included changes within several classes. I created a DateRange class that was a superclass for Reservations and Blocks. Since Blocks and Reservations need to utilize the same features such as a check_in date, a check_out date, and a way to check for room availability, this allowed for one class to take care of all those features as well as check for date validity. This creates for code that is more DRY as well as classes that are easier to re-use and change. Within the Hotel class I changed to responsibility for checking for an overlap between the dates requested to check in and the rooms in the hotel to the Date Range class. My tests proved useful when I ran rake and found a few failures that were due to my change in code and they pointed me in the right direction. I found myself extremely grateful for the existence of tests!


-- create a date range class that is a superclass to reservation and block
-- take overlap from hotel class and put it into date range class.
18 changes: 18 additions & 0 deletions lib/block.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative 'date_range.rb'

module Hotel
class Block < DateRange

attr_reader :check_in, :check_out, :id, :rooms_in_block, :discount

def initialize(check_in, check_out, id)
super(check_in, check_out)
@id = id
@rooms_in_block = []
end

def add_room(room)
@rooms_in_block << room
end
end # end of block class
end # end of Hotel module
Loading