Tuesday, April 15, 2014

Chapter 7

This week we were assigned exercises from Chapter 7 in our text, Software Development.

7.1 Not all the tables in RMH Homebase satisfy all six database normalization criteria. For example, dbDates doesn't satisfy either criterion 5 or criterion 6. Give another example of how a RMH Homebase table violations normalization criteria 5. Give another example of how a table violates criterion 6. Explain why either of these anomalies can cause a problem - create more programming work or introduce an error - when updating one of these tables.

What are the six database normalization criteria?

  1. The rows can be rearranged without changing the meaning of the table.
  2. The columns can be rearranged without changing the meaning of the table.
  3. No two rows of a table are identical.  This is often accomplished by defining one column whose values are mutually unique.  This column is known as the table's primary key.
  4. No row has any hidden components, such as an object id or a timestamp.
  5. Every entry in the table has exactly one value of the appropriate type.
  6. No attribute in the table is redundant with the primary key.

The persons field of dbSchedule violates criterion 5 by allowing multiple values to be inserted.  When you try to query an entry with multiple values, this creates more complexity than is needed and can have unwanted side effects.  It is better to keep things as straightforward, organized, and simple as possible.

The id field of dbPersons violates criterion 6.  This field combines the first_name and phone1 fields creating redundancy and causing the primary key to be non-unique.  If, for example, a father and son (John-senior and John-junior) who not only share the same first name, but also the same phone number, are entered into this database and a query is run- it would result in two records that would try and use the same id value- what a mess!

7.2 Develop and unit test the functions get_shift_month, get_shift_day, get_shift_year, get_shift_start, and get_shift_end for the dbShifts.php module that are called by the new get_shift_name_from_id function shown in Figure 7.14.

For this exercise, I consulted with my Team FOSSils.

The first step to this exercise was to modify the get_shift_name_from_id function to the following:

function get_shift_name_from_id($id) { 
     $shift_name=date("l, F jS, Y", 
         mktime(0,0,0,get_shift_month($id),get_shift_day($id),
         get_shift_year($id))); 
     $special_cases = array ( 
         "night" => " night shift", "chef" => " guest chef"); 
     if (array_key_exists(substr($id, 9), $special_cases)) 
         $shift_name = $shift_name . $special_cases[substr($id, 9)]; 
     else{ 
         if (strpos($id, "Fam") !== false) 
             $shift_name = $shift_name . " Family Room "; 
         $shift_name = $shift_name . " from "; 
         $st = get_shift_start($id); 
         $et = get_shift_end($id); 
         $st = $st <12 ? $st . "am" : $st - 12 . "pm"; 
         if ($st == "0pm") 
             $st = "12pm"; 
         $et = $et <12 ? $et . "am" : $et - 12 . "pm";
         if ($et == "0pm") $et = "12pm"; 
         $shift_name = $shift_name . $st . " to " . $et; 
     } 
     return $shift_name; 
}

To implement the rest of this exercise, I decided to create some simple getters for the functions to be tested such as:

function get_shift_month($id) {
    return substr($id, 0, 2);
}

We then made up some simple assertion unit tests like the following:

$this->assertTrue(get_shift_month() == "01");
$this->assertTrue(get_shift_day() == "01");
$this->assertTrue(get_shift_year() == "01");

Exercise 7.3 – Design, implement, and unit test the changes to the database modules required by the new feature Item 4: Calendar month views in the "wish list" described in Appendix B.

After having read this question multiple times, consulting Appendix B, AND attempting to modify dbWeeks implementation; I have come to the conclusion that this is an impossible exercise.  I am planning on consulting with my fellow students in class.



Tuesday, April 8, 2014

Chapter 6

This weeks blog revolves around Chapter 6 in our text Software Development.

1) For the Person class, define a new pair of functions to set and retrieve the value of the variables $employer, $contact_person, and $contact_phone in preparation for implementing new features 1 and 9d in RMH Homebase.

First add the variables to the person class:

private $employer;
private $contact_person;
private $contact_phone;

Then we create the getters: 

function get_employer(){
    return $this->employer;
}
function get_contact_person(){
    return $this->contact_person;
}
function get_contact_phone(){
    return $this->contact_phone;
}

Then we create the setters: 

function set_employer(emp){
    $this->employer=$emp;
}
function set_contact_person(cPerson){
    $this->contact_person = $cPerson;
}
function set_contact_phone(cPhone){
    $this->contact_phone = $cPhone;
}

2) Add four new parameters and corresponding assignments to the constructor for the Person class, so that the status, employer, contact person, and contact person's phone are properly initialized. Use the following prototype for your new constructor:

function __construct($f, $1, $a, $c, $s, $z, $p1, $p2, $e, $t, $status, $employer, $contact, $contact_phone, ...)

function __construct($f, $l, $a, $c, $s, $z, $p1, $p2, $e, $t, $stat, $emp, $cPerson, $cPhone, ....)

$this->status = stat;
$this->employer = emp;
$this->contact_person = cPerson;
$this->contact_phone = cPhone;

3) The set_status function defined in this chapter does not check that the $value passed is valid: either active or inactive. Thus whatever $value is passed becomes a Person's status. Suggest a modification of this function that would perform that check. What value should it assign to a Person's status when the $value passed is invalid? Discuss the unit testing implications of your design decision. 

function set_status($value){
   if (strcasecmp($value,"active") == 0){
      $this->status = $value;
   }
   elseif (strcasecmp($value,"inactive") == 0) {
      $this->status = $value;
   }
   else{
      $this->status = NULL;
   }
}

Test $value as the following:
  • empty value
  • "active"
  • "ACTIVE"
  • "inactive"
  • "INACTIVE"
4) Refactor the existing Person class by removing all the mutators that are not called from anywhere in the code base. Be sure to test your changes by rerunning the test suite. 

I attempted to complete this exercise by using CTRL-F to search for any setter methods.  Unfortunately,   I was unable to find any.   I am unsure how to proceed.

Tuesday, April 1, 2014

Meeting Charleston

Team FOSSil decided to attend Tech After 5 on Tuesday of last week along with Diana from the AM class.  Tech after 5 is an event that is held once a month on a Tuesday.  It is an event for tech professionals looking to network in Charleston, SC.  They also have these events in other major cities in the US.  To attend an event you have to Register online, which is completely free, and then simply show up!  Once you are there, you are to sign-in, grab your name tag, grab a drink (which is also FREE), and start networking.  I really liked that they provided extra stickers that let people know why you were there.  All of us FOSSils had stickers that said "Hire me!".  We spent the rest of the evening schmoozing and speaking with different people.  We talked to some people from Benefit Focus and Blackbaud.  Unfortunately, we saw a lot more "Hire me!" stickers and not more "I'm looking to hire" stickers.  There were so many students...even nursing students??  Not exactly sure why.

It was good experience for all of us to learn how to talk to people and how to engage them.  It can be quite nerve wracking to be in a situation like that, so it's definitely important to practice.  Overall, I think our group did great- we handed out some resumes, got some contact info, and bonded more with each other.  It was a good time and something I'll always remember.