David Rivera
DRAI - Universidad de Antioquia
“ Permiten dar estructura al software convirtiendolo más flexible y mantenible ”Robert C. Martin
Cada elemento es almacenado una única vez
Las modificaciones se realizan en un solo lugar
Evitar el Copy/Paste en el código
console.log( fiveSquared() );
console.log( sixSquared() );
console.log( sevenSquared() );
function fiveSquared() {
return 5 * 5;
}
function sixSquared() {
return 6 * 6;
}
function sevenSquared() {
return 7 * 7;
}
console.log( squared(5) );
console.log( squared(6) );
console.log( squared(7) );
function squared( num ) {
return num * num;
}
public String weekday1(int dayOfWeek) {
switch (dayOfWeek) {
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
case 7: return "Sunday";
default:
throw new IllegalArgumentException(
"dayOfWeek must be in range 1..7");
}
}
public String weekday2(int dayOfWeek){
if ((dayOfWeek < 1) || (dayOfWeek > 7))
throw new
IllegalArgumentException(
"dayOfWeek must be in range 1..7");
final String[] weekdays = {
"Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday",
"Sunday"};
return weekdays[dayOfWeek-1];
}
import os, sys
import os
import sys
private int x;
private Color color;
private int x;
private Color color;
...focusing on writing only the code necessary to pass tests, designs can often be cleaner and clearer than is achieved by other methods.