From d1fef172d2c3c824436dfce5c621feb1e424b311 Mon Sep 17 00:00:00 2001 From: TheDG Date: Thu, 29 Sep 2016 13:01:24 -0300 Subject: [PATCH 1/2] First commit. Change code missing --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ customer.rb | 8 +++++++- movie.rb | 2 +- rental.rb | 1 + 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..9bada57 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# Actividad 4-iic2113 + +### Integrantes + +Nombre | GitHub +-------------- | ------- +Agustin Gomez | agomez4 +Diego Sinay | TheDG +Maria Fernada Sepulveda | mf22 + + +### Code Smells + +1. Switch statements +Línea 21 customers.rb +Se tiene un switch complejo + +2. Data Class +Clase Rental +Solo se define atributos, no contiene comportamiento, Se arregla con 1. + +3. Shotgun Surgey +Clase Rental, comportamiento segmentado en varios lados + +4.Data Class +Clase Movie +Solo se define atributos, no contiene comportamiento, Se arregla con 1. + +5. Long Method +Customer linea 14 : statement +Statement tiene más de 10 lineas de codigo + +6. Large Class +Customer +Excesivos metodos-->Statement pertenece a objecto caja, no cliente. + + + + + + + diff --git a/customer.rb b/customer.rb index dbc96b1..9c744b1 100644 --- a/customer.rb +++ b/customer.rb @@ -22,18 +22,24 @@ def statement when Movie::REGULAR this_amount += 2 this_amount += (element.days_rented - 2) * 1.5 if element.days_rented > 2 + return this_amount when Movie::NEW_RELEASE this_amount += element.days_rented * 3 + return this_amount when Movie::CHILDRENS this_amount += 1.5 this_amount += (element.days_rented - 3) * 1.5 if element.days_rented > 3 + return this_amount end + #Arreglo + this_amount+=element.get_price() + # add frequent renter points frequent_renter_points += 1 # add bonus for a two day new release rental - if element.movie.price_code == Movie::NEW_RELEASE && element.days_rented > 1 + if element.movie.price_code == Movie::NEW_RELEASE && element.element.days_rented > 1 frequent_renter_points += 1 end diff --git a/movie.rb b/movie.rb index 86f1a3c..db9350e 100644 --- a/movie.rb +++ b/movie.rb @@ -8,5 +8,5 @@ class Movie def initialize(title, price_code) @title, @price_code = title, price_code - end + end end diff --git a/rental.rb b/rental.rb index e275201..1f731ee 100644 --- a/rental.rb +++ b/rental.rb @@ -5,4 +5,5 @@ class Rental def initialize(movie, days_rented) @movie, @days_rented = movie, days_rented end + end \ No newline at end of file From bbad84c8329bf2d8cf3441040fef45badff33e7f Mon Sep 17 00:00:00 2001 From: TheDG Date: Thu, 29 Sep 2016 13:14:25 -0300 Subject: [PATCH 2/2] Read me Complete --- README.md | 31 +++++++++++++++++-------------- customer.rb | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9bada57..aedf6ae 100644 --- a/README.md +++ b/README.md @@ -12,27 +12,30 @@ Maria Fernada Sepulveda | mf22 ### Code Smells 1. Switch statements -Línea 21 customers.rb -Se tiene un switch complejo +* Línea 21 `customers.rb` +* Se tiene un switch complejo. +* Solución: Controlar la condición booleana de los case en solo una, en vez de comparar uno por uno, se puede añadir directamente. 2. Data Class -Clase Rental -Solo se define atributos, no contiene comportamiento, Se arregla con 1. +* Class Rental `rental.rb`, Class Movie `movie.rb*` +* Solo se definen atributos, no contienen comportamiento. +* Solución: Dado que Ruby es un lenguaje orientado a objetos, cada una de sus clases podría tener los métodos para acceder a sus clases y modificar el modelo. 3. Shotgun Surgey -Clase Rental, comportamiento segmentado en varios lados +* Class Rental +* Comportamiento segmentado en varios lados, o en este caso, se le quito el comportamiento y se asigno en otra clase. +* Solución: Darle comportamiento a Rental, y no asignar todo a Costumer. -4.Data Class -Clase Movie -Solo se define atributos, no contiene comportamiento, Se arregla con 1. +4. Long Method +* Linea 14 `customers.rb` : statement +* Statement tiene más de 10 lineas de código. +* Solución: Particionar el comportamiento de `statement`. -5. Long Method -Customer linea 14 : statement -Statement tiene más de 10 lineas de codigo +5. Large Class +* Class Customer +* Excesivos metodos--> Statement pertenece a algun otro objecto caja o boleta, al cliente no cliente. +* Solución: Crear una nueva clase que encapsule esta funcionalidad. -6. Large Class -Customer -Excesivos metodos-->Statement pertenece a objecto caja, no cliente. diff --git a/customer.rb b/customer.rb index 9c744b1..5c8f412 100644 --- a/customer.rb +++ b/customer.rb @@ -19,6 +19,7 @@ def statement this_amount = 0 # determine amounts for each line case element.movie.price_code + when Movie::REGULAR this_amount += 2 this_amount += (element.days_rented - 2) * 1.5 if element.days_rented > 2