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.

No comments:

Post a Comment