Refactoring in AS3

Eddie Kao
Eddie KaoManager at Kaos' Digital Network, Ltd.
Refactoring in AS3
http://blog.eddie.com.tw
aquarianboy@ptt
eddie@adcube.com.tw
aquarianboy@plurk
eddiekao@facebook
Refactoring in AS3
AS3   OOP   Design Pattern
...
Refactoring...?
B
!?
?
!=
?
?
?
duplicated code, long method, large class, long parameter list...
If it stinks, change it.
Rule of Three
Three strikes and you refactor
?
?

    !
        ...
?
    ...


          !
?
    ...


          !
Design Pattern
                 (over-engineering)
Design Pattern v.s. Refactoring
Refactoring in AS3
!
&
!
..


1.
2.
3.



           2   2   2           1.5
         1.5   3   3           1.5
                           3



     1                 1             1
Extract Method
            ...
// Customer.as                                                     // Customer.as
public function checkout ():String                                 public function checkout():String
{                                                                  {
  ...                                                                while(rentals.length > 0)
  while(rentals.length > 0)                                          {
  {                                                                    ...
    ...
    ...                                                                     this_amount = amount_for(the_rental);
                                                                            ...
      switch(the_rental.get_movie().get_price_code())                  }
      {                                                                ..
        case Movie.REGULAR: //                                     }
          this_amount += 2;
          if (the_rental.get_days_rented() > 2)                    private function amount_for (the_rental:Rental):Number
          {                                                        {
            this_amount+=(the_rental.get_days_rented()-2)* 1.5;      var result:int = 0;
          }                                                          switch (the_rental.get_movie().get_price_code())
          break;                                                     {
                                                                       case Movie.REGULAR ://
          case Movie.NEW_RELEASE: //                                   result += 2;
            this_amount += the_rental.get_days_rented() * 3;           if (the_rental.get_days_rented() > 2)
            break;                                                     {
                                                                         result += (the_rental.get_days_rented() - 2) * 1.5;
          case Movie.CHILDRENS: //                                     }
            this_amount += 1.5;                                        break;
            if (the_rental.get_days_rented() > 3)
            {                                                               case Movie.NEW_RELEASE ://
              this_amount+=(the_rental.get_days_rented()-3)*1.5;              result += the_rental.get_days_rented() * 3;
            }                                                                 break;
            break;
      }                                                                     case Movie.CHILDRENS ://
    ...                                                                       result += 1.5;
}                                                                             if (the_rental.get_days_rented() > 3)
                                                                              {
                                                                                result += (the_rental.get_days_rented() - 3) * 1.5;
                                                                              }
                                                                              break;
                                                                       }

                                                                       return result;
                                                                   }
// Customer.as                                                     // Customer.as
public function checkout ():String                                 public function checkout():String
{                                                                  {
  ...                                                                while(rentals.length > 0)
  while(rentals.length > 0)                                          {
  {                                                                    ...
    ...
    ...                                                                     this_amount = amount_for(the_rental);
                                                                            ...
      switch(the_rental.get_movie().get_price_code())                  }
      {                                                                ..
        case Movie.REGULAR: //                                     }
          this_amount += 2;
          if (the_rental.get_days_rented() > 2)                    private function amount_for (the_rental:Rental):Number
          {                                                        {
            this_amount+=(the_rental.get_days_rented()-2)* 1.5;      var result:int = 0;
          }                                                          switch (the_rental.get_movie().get_price_code())
          break;                                                     {
                                                                       case Movie.REGULAR ://
          case Movie.NEW_RELEASE: //                                   result += 2;
            this_amount += the_rental.get_days_rented() * 3;           if (the_rental.get_days_rented() > 2)
            break;                                                     {
                                                                         result += (the_rental.get_days_rented() - 2) * 1.5;
          case Movie.CHILDRENS: //                                     }
            this_amount += 1.5;                                        break;
            if (the_rental.get_days_rented() > 3)
            {                                                               case Movie.NEW_RELEASE ://
              this_amount+=(the_rental.get_days_rented()-3)*1.5;              result += the_rental.get_days_rented() * 3;
            }                                                                 break;
            break;
      }                                                                     case Movie.CHILDRENS ://
    ...                                                                       result += 1.5;
}                                                                             if (the_rental.get_days_rented() > 3)
                                                                              {
                                                                                result += (the_rental.get_days_rented() - 3) * 1.5;
                                                                              }
                                                                              break;
                                                                       }

                                                                       return result;
                                                                   }
// Customer.as                                                     // Customer.as
public function checkout ():String                                 public function checkout():String
{                                                                  {
  ...                                                                while(rentals.length > 0)
  while(rentals.length > 0)                                          {
  {                                                                    ...
    ...
    ...                                                                     this_amount = amount_for(the_rental);
                                                                            ...
      switch(the_rental.get_movie().get_price_code())                  }
      {                                                                ..
        case Movie.REGULAR: //                                     }
          this_amount += 2;
          if (the_rental.get_days_rented() > 2)                    private function amount_for (the_rental:Rental):Number
          {                                                        {
            this_amount+=(the_rental.get_days_rented()-2)* 1.5;      var result:int = 0;
          }                                                          switch (the_rental.get_movie().get_price_code())
          break;                                                     {
                                                                       case Movie.REGULAR ://
          case Movie.NEW_RELEASE: //                                   result += 2;
            this_amount += the_rental.get_days_rented() * 3;           if (the_rental.get_days_rented() > 2)
            break;                                                     {
                                                                         result += (the_rental.get_days_rented() - 2) * 1.5;
          case Movie.CHILDRENS: //                                     }
            this_amount += 1.5;                                        break;
            if (the_rental.get_days_rented() > 3)
            {                                                               case Movie.NEW_RELEASE ://
              this_amount+=(the_rental.get_days_rented()-3)*1.5;              result += the_rental.get_days_rented() * 3;
            }                                                                 break;
            break;
      }                                                                     case Movie.CHILDRENS ://
    ...                                                                       result += 1.5;
}                                                                             if (the_rental.get_days_rented() > 3)
                                                                              {
                                                                                result += (the_rental.get_days_rented() - 3) * 1.5;
                                                                              }
                                                                              break;
                                                                       }

                                                                       return result;
                                                                   }
// Customer.as                                                     // Customer.as
public function checkout ():String                                 public function checkout():String
{                                                                  {
  ...                                                                while(rentals.length > 0)
  while(rentals.length > 0)                                          {
  {                                                                    ...
    ...
    ...                                                                     this_amount = amount_for(the_rental);
                                                                            ...
      switch(the_rental.get_movie().get_price_code())                  }
      {                                                                ..
        case Movie.REGULAR: //                                     }
          this_amount += 2;
          if (the_rental.get_days_rented() > 2)                    private function amount_for (the_rental:Rental):Number
          {                                                        {
            this_amount+=(the_rental.get_days_rented()-2)* 1.5;      var result:int = 0;
          }                                                          switch (the_rental.get_movie().get_price_code())
          break;                                                     {
                                                                       case Movie.REGULAR ://
          case Movie.NEW_RELEASE: //                                   result += 2;
            this_amount += the_rental.get_days_rented() * 3;           if (the_rental.get_days_rented() > 2)
            break;                                                     {
                                                                         result += (the_rental.get_days_rented() - 2) * 1.5;
          case Movie.CHILDRENS: //                                     }
            this_amount += 1.5;                                        break;
            if (the_rental.get_days_rented() > 3)
            {                                                               case Movie.NEW_RELEASE ://
              this_amount+=(the_rental.get_days_rented()-3)*1.5;              result += the_rental.get_days_rented() * 3;
            }                                                                 break;
            break;
      }                                                                     case Movie.CHILDRENS ://
    ...                                                                       result += 1.5;
}                                                                             if (the_rental.get_days_rented() > 3)
                                                                              {
                                                                                result += (the_rental.get_days_rented() - 3) * 1.5;
                                                                              }
                                                                              break;
                                                                       }

                                                                       return result;
                                                                   }
Move Method
method            ...
// Customer.as                                                         // Customer.as
public class Customer                                                  public class Customer
{                                                                      {
  ..                                                                     private function amount_for (the_rental:Rental):Number
  private function amount_for (the_rental:Rental):Number                 {
  {                                                                        return the_rental.get_charge();
     var result:int = 0;                                                 }
     switch (the_rental.get_movie().get_price_code())                  }
     {
       case Movie.REGULAR ://                                          // Rental.as
       result += 2;                                                    public class Rental
       if (the_rental.get_days_rented() > 2)                           {
       {                                                                 ...
         result += (the_rental.get_days_rented() - 2) * 1.5;             public function get_charge():Number
       }                                                                 {
       break;                                                              var result:int = 0;
                                                                           switch (get_movie().get_price_code())
             case Movie.NEW_RELEASE ://                                    {
               result += the_rental.get_days_rented() * 3;                   case Movie.REGULAR ://
               break;                                                          result += 2;
                                                                               if (get_days_rented() > 2)
             case Movie.CHILDRENS ://                                          {
               result += 1.5;                                                    result += (get_days_rented() - 2) * 1.5;
               if (the_rental.get_days_rented() > 3)                           }
               {                                                               break;
                 result += (the_rental.get_days_rented() - 3) * 1.5;
               }                                                                 case Movie.NEW_RELEASE ://
               break;                                                              result += get_days_rented() * 3;
         }                                                                         break;

         return result;                                                          case Movie.CHILDRENS ://
    }                                                                              result += 1.5;
    ..                                                                             if (get_days_rented() > 3)
}                                                                                  {
                                                                                     result += (get_days_rented() - 3) * 1.5;
                                                                                   }
                                                                                   break;
                                                                             }

                                                                             return result;
                                                                           }
                                                                           ...
                                                                       }
// Customer.as                                                         // Customer.as
public class Customer                                                  public class Customer
{                                                                      {
  ..                                                                     private function amount_for (the_rental:Rental):Number
  private function amount_for (the_rental:Rental):Number                 {
  {                                                                        return the_rental.get_charge();
     var result:int = 0;                                                 }
     switch (the_rental.get_movie().get_price_code())                  }
     {
       case Movie.REGULAR ://                                          // Rental.as
       result += 2;                                                    public class Rental
       if (the_rental.get_days_rented() > 2)                           {
       {                                                                 ...
         result += (the_rental.get_days_rented() - 2) * 1.5;             public function get_charge():Number
       }                                                                 {
       break;                                                              var result:int = 0;
                                                                           switch (get_movie().get_price_code())
             case Movie.NEW_RELEASE ://                                    {
               result += the_rental.get_days_rented() * 3;                   case Movie.REGULAR ://
               break;                                                          result += 2;
                                                                               if (get_days_rented() > 2)
             case Movie.CHILDRENS ://                                          {
               result += 1.5;                                                    result += (get_days_rented() - 2) * 1.5;
               if (the_rental.get_days_rented() > 3)                           }
               {                                                               break;
                 result += (the_rental.get_days_rented() - 3) * 1.5;
               }                                                                 case Movie.NEW_RELEASE ://
               break;                                                              result += get_days_rented() * 3;
         }                                                                         break;

         return result;                                                          case Movie.CHILDRENS ://
    }                                                                              result += 1.5;
    ..                                                                             if (get_days_rented() > 3)
}                                                                                  {
                                                                                     result += (get_days_rented() - 3) * 1.5;
                                                                                   }
                                                                                   break;
                                                                             }

                                                                             return result;
                                                                           }
                                                                           ...
                                                                       }
// Customer.as                                                         // Customer.as
public class Customer                                                  public class Customer
{                                                                      {
  ..                                                                     private function amount_for (the_rental:Rental):Number
  private function amount_for (the_rental:Rental):Number                 {
  {                                                                        return the_rental.get_charge();
     var result:int = 0;                                                 }
     switch (the_rental.get_movie().get_price_code())                  }
     {
       case Movie.REGULAR ://                                          // Rental.as
       result += 2;                                                    public class Rental
       if (the_rental.get_days_rented() > 2)                           {
       {                                                                 ...
         result += (the_rental.get_days_rented() - 2) * 1.5;             public function get_charge():Number
       }                                                                 {
       break;                                                              var result:int = 0;
                                                                           switch (get_movie().get_price_code())
             case Movie.NEW_RELEASE ://                                    {
               result += the_rental.get_days_rented() * 3;                   case Movie.REGULAR ://
               break;                                                          result += 2;
                                                                               if (get_days_rented() > 2)
             case Movie.CHILDRENS ://                                          {
               result += 1.5;                                                    result += (get_days_rented() - 2) * 1.5;
               if (the_rental.get_days_rented() > 3)                           }
               {                                                               break;
                 result += (the_rental.get_days_rented() - 3) * 1.5;
               }                                                                 case Movie.NEW_RELEASE ://
               break;                                                              result += get_days_rented() * 3;
         }                                                                         break;

         return result;                                                          case Movie.CHILDRENS ://
    }                                                                              result += 1.5;
    ..                                                                             if (get_days_rented() > 3)
}                                                                                  {
                                                                                     result += (get_days_rented() - 3) * 1.5;
                                                                                   }
                                                                                   break;
                                                                             }

                                                                             return result;
                                                                           }
                                                                           ...
                                                                       }
// Customer.as                                                         // Customer.as
public class Customer                                                  public class Customer
{                                                                      {
  ..                                                                     private function amount_for (the_rental:Rental):Number
  private function amount_for (the_rental:Rental):Number                 {
  {                                                                        return the_rental.get_charge();
     var result:int = 0;                                                 }
     switch (the_rental.get_movie().get_price_code())                  }
     {
       case Movie.REGULAR ://                                          // Rental.as
       result += 2;                                                    public class Rental
       if (the_rental.get_days_rented() > 2)                           {
       {                                                                 ...
         result += (the_rental.get_days_rented() - 2) * 1.5;             public function get_charge():Number
       }                                                                 {
       break;                                                              var result:int = 0;
                                                                           switch (get_movie().get_price_code())
             case Movie.NEW_RELEASE ://                                    {
               result += the_rental.get_days_rented() * 3;                   case Movie.REGULAR ://
               break;                                                          result += 2;
                                                                               if (get_days_rented() > 2)
             case Movie.CHILDRENS ://                                          {
               result += 1.5;                                                    result += (get_days_rented() - 2) * 1.5;
               if (the_rental.get_days_rented() > 3)                           }
               {                                                               break;
                 result += (the_rental.get_days_rented() - 3) * 1.5;
               }                                                                 case Movie.NEW_RELEASE ://
               break;                                                              result += get_days_rented() * 3;
         }                                                                         break;

         return result;                                                          case Movie.CHILDRENS ://
    }                                                                              result += 1.5;
    ..                                                                             if (get_days_rented() > 3)
}                                                                                  {
                                                                                     result += (get_days_rented() - 3) * 1.5;
                                                                                   }
                                                                                   break;
                                                                             }

                                                                             return result;
                                                                           }
                                                                           ...
                                                                       }
// Customer.as                                                  // Customer.as
public class Customer                                           public class Customer
{                                                               {
  ..                                                              ..
  public function checkout ():String                              public function checkout ():String
  {                                                               {
     var total_amount:Number = 0;//                                  var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                     var bonus_points:int = 0;//
     var rentals:Array = _rentals;                                   var rentals:Array = _rentals;
     var result:String = get_name() +"               n";            var result:String = get_name() +"                n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var this_amount:Number = 0;                                     var this_amount:Number = 0;
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

             this_amount = amount_for(the_rental);                           this_amount = the_rental.get_charge();

             //                                                              //
             bonus_points += 1;                                              bonus_points += 1;
             ...                                                             ...
         }                                                               }

         result += "n        " + total_amount + "n";                   result += "n        " + total_amount + "n";
         result += "          " + bonus_points + " ";                    result += "          " + bonus_points + " ";

         return result;                                                  return result;
    }                                                               }
    ..                                                              ..
}                                                               }
// Customer.as                                                  // Customer.as
public class Customer                                           public class Customer
{                                                               {
  ..                                                              ..
  public function checkout ():String                              public function checkout ():String
  {                                                               {
     var total_amount:Number = 0;//                                  var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                     var bonus_points:int = 0;//
     var rentals:Array = _rentals;                                   var rentals:Array = _rentals;
     var result:String = get_name() +"               n";            var result:String = get_name() +"                n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var this_amount:Number = 0;                                     var this_amount:Number = 0;
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

             this_amount = amount_for(the_rental);                           this_amount = the_rental.get_charge();

             //                                                              //
             bonus_points += 1;                                              bonus_points += 1;
             ...                                                             ...
         }                                                               }

         result += "n        " + total_amount + "n";                   result += "n        " + total_amount + "n";
         result += "          " + bonus_points + " ";                    result += "          " + bonus_points + " ";

         return result;                                                  return result;
    }                                                               }
    ..                                                              ..
}                                                               }
// Customer.as                                                  // Customer.as
public class Customer                                           public class Customer
{                                                               {
  ..                                                              ..
  public function checkout ():String                              public function checkout ():String
  {                                                               {
     var total_amount:Number = 0;//                                  var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                     var bonus_points:int = 0;//
     var rentals:Array = _rentals;                                   var rentals:Array = _rentals;
     var result:String = get_name() +"               n";            var result:String = get_name() +"                n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var this_amount:Number = 0;                                     var this_amount:Number = 0;
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

             this_amount = amount_for(the_rental);                           this_amount = the_rental.get_charge();

             //                                                              //
             bonus_points += 1;                                              bonus_points += 1;
             ...                                                             ...
         }                                                               }

         result += "n        " + total_amount + "n";                   result += "n        " + total_amount + "n";
         result += "          " + bonus_points + " ";                    result += "          " + bonus_points + " ";

         return result;                                                  return result;
    }                                                               }
    ..                                                              ..
}                                                               }
Replace Temp with Query
                   ...
// Customer.as                                                   // Customer.as
public function checkout ():String                               public function checkout ():String
{                                                                {
  var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
  var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
  var rentals:Array = _rentals;                                    var rentals:Array = _rentals;
  var result:String = get_name() +"           n";                 var result:String = get_name() +"          n";

    while (rentals.length > 0)                                       while (rentals.length > 0)
    {                                                                {
      var this_amount:Number = 0;                                      var the_rental:Rental = rentals.shift() as Rental;
      var the_rental:Rental = rentals.shift() as Rental;
                                                                       //
      this_amount = amount_for(the_rental);                            bonus_points += 1;

      //                                                             //                   2    1
      bonus_points += 1;                                             if ((the_rental.get_movie().get_price_code() ==
                                                                 Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))
    //                   2    1                                      {
    if ((the_rental.get_movie().get_price_code() ==                     bonus_points += 1;
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))            }
    {                                                                result += "-" + the_rental.get_movie().get_title() + " " +
       bonus_points += 1;                                        the_rental.get_charge() +" n";
    }                                                                total_amount += the_rental.get_charge();
    result += "-" + the_rental.get_movie().get_title() + " " +     }
this_amount +" n";
    total_amount += this_amount;                                     result += "n      " + total_amount + "n";
  }                                                                  result += "        " + bonus_points + " ";

    result += "n      " + total_amount + "n";                      return result;
    result += "        " + bonus_points + " ";                   }

    return result;
}
// Customer.as                                                   // Customer.as
public function checkout ():String                               public function checkout ():String
{                                                                {
  var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
  var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
  var rentals:Array = _rentals;                                    var rentals:Array = _rentals;
  var result:String = get_name() +"           n";                 var result:String = get_name() +"          n";

    while (rentals.length > 0)                                       while (rentals.length > 0)
    {                                                                {
      var this_amount:Number = 0;                                      var the_rental:Rental = rentals.shift() as Rental;
      var the_rental:Rental = rentals.shift() as Rental;
                                                                       //
      this_amount = amount_for(the_rental);                            bonus_points += 1;

      //                                                             //                   2    1
      bonus_points += 1;                                             if ((the_rental.get_movie().get_price_code() ==
                                                                 Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))
    //                   2    1                                      {
    if ((the_rental.get_movie().get_price_code() ==                     bonus_points += 1;
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))            }
    {                                                                result += "-" + the_rental.get_movie().get_title() + " " +
       bonus_points += 1;                                        the_rental.get_charge() +" n";
    }                                                                total_amount += the_rental.get_charge();
    result += "-" + the_rental.get_movie().get_title() + " " +     }
this_amount +" n";
    total_amount += this_amount;                                     result += "n      " + total_amount + "n";
  }                                                                  result += "        " + bonus_points + " ";

    result += "n      " + total_amount + "n";                      return result;
    result += "        " + bonus_points + " ";                   }

    return result;
}
// Customer.as                                                   // Customer.as
public function checkout ():String                               public function checkout ():String
{                                                                {
  var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
  var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
  var rentals:Array = _rentals;                                    var rentals:Array = _rentals;
  var result:String = get_name() +"           n";                 var result:String = get_name() +"          n";

    while (rentals.length > 0)                                       while (rentals.length > 0)
    {                                                                {
      var this_amount:Number = 0;                                      var the_rental:Rental = rentals.shift() as Rental;
      var the_rental:Rental = rentals.shift() as Rental;
                                                                       //
      this_amount = amount_for(the_rental);                            bonus_points += 1;

      //                                                             //                   2    1
      bonus_points += 1;                                             if ((the_rental.get_movie().get_price_code() ==
                                                                 Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))
    //                   2    1                                      {
    if ((the_rental.get_movie().get_price_code() ==                     bonus_points += 1;
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))            }
    {                                                                result += "-" + the_rental.get_movie().get_title() + " " +
       bonus_points += 1;                                        the_rental.get_charge() +" n";
    }                                                                total_amount += the_rental.get_charge();
    result += "-" + the_rental.get_movie().get_title() + " " +     }
this_amount +" n";
    total_amount += this_amount;                                     result += "n      " + total_amount + "n";
  }                                                                  result += "        " + bonus_points + " ";

    result += "n      " + total_amount + "n";                      return result;
    result += "        " + bonus_points + " ";                   }

    return result;
}
Extract Method
                 ...
// Customer.as                                                   // Customer.as

public function checkout ():String                               public function checkout ():String
{                                                                {
  ... while (rentals.length > 0)                                   ...
  {                                                                while (rentals.length > 0)
    var this_amount:Number = 0;                                    {
    var the_rental:Rental = rentals.shift() as Rental;               var this_amount:Number = 0;
                                                                     var the_rental:Rental = rentals.shift() as Rental;
    this_amount = amount_for(the_rental);
                                                                     this_amount = amount_for(the_rental);
    //
    bonus_points += 1;                                               //
                                                                     bonus_points += the_rental.get_bonus_points();
    //                   2    1
    if ((the_rental.get_movie().get_price_code() ==                  result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))        this_amount +" n";
    {                                                                total_amount += this_amount;
       bonus_points += 1;                                          }
    }                                                              ...
                                                                 }
    result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n";                                              // Rental.as
    total_amount += this_amount;                                 public class Rental
  }                                                              {
  ...                                                              ..
}                                                                  public function get_bonus_points():int
                                                                   {
                                                                      //                  2     1
                                                                      if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
                                                                 (get_days_rented() > 1))
                                                                      {
                                                                         return 2;
                                                                      }
                                                                      else
                                                                      {
                                                                         return 1;
                                                                      }
                                                                   }
                                                                   ..
                                                                 }
// Customer.as                                                   // Customer.as

public function checkout ():String                               public function checkout ():String
{                                                                {
  ... while (rentals.length > 0)                                   ...
  {                                                                while (rentals.length > 0)
    var this_amount:Number = 0;                                    {
    var the_rental:Rental = rentals.shift() as Rental;               var this_amount:Number = 0;
                                                                     var the_rental:Rental = rentals.shift() as Rental;
    this_amount = amount_for(the_rental);
                                                                     this_amount = amount_for(the_rental);
    //
    bonus_points += 1;                                               //
                                                                     bonus_points += the_rental.get_bonus_points();
    //                   2    1
    if ((the_rental.get_movie().get_price_code() ==                  result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))        this_amount +" n";
    {                                                                total_amount += this_amount;
       bonus_points += 1;                                          }
    }                                                              ...
                                                                 }
    result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n";                                              // Rental.as
    total_amount += this_amount;                                 public class Rental
  }                                                              {
  ...                                                              ..
}                                                                  public function get_bonus_points():int
                                                                   {
                                                                      //                  2     1
                                                                      if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
                                                                 (get_days_rented() > 1))
                                                                      {
                                                                         return 2;
                                                                      }
                                                                      else
                                                                      {
                                                                         return 1;
                                                                      }
                                                                   }
                                                                   ..
                                                                 }
// Customer.as                                                   // Customer.as

public function checkout ():String                               public function checkout ():String
{                                                                {
  ... while (rentals.length > 0)                                   ...
  {                                                                while (rentals.length > 0)
    var this_amount:Number = 0;                                    {
    var the_rental:Rental = rentals.shift() as Rental;               var this_amount:Number = 0;
                                                                     var the_rental:Rental = rentals.shift() as Rental;
    this_amount = amount_for(the_rental);
                                                                     this_amount = amount_for(the_rental);
    //
    bonus_points += 1;                                               //
                                                                     bonus_points += the_rental.get_bonus_points();
    //                   2    1
    if ((the_rental.get_movie().get_price_code() ==                  result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))        this_amount +" n";
    {                                                                total_amount += this_amount;
       bonus_points += 1;                                          }
    }                                                              ...
                                                                 }
    result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n";                                              // Rental.as
    total_amount += this_amount;                                 public class Rental
  }                                                              {
  ...                                                              ..
}                                                                  public function get_bonus_points():int
                                                                   {
                                                                      //                  2     1
                                                                      if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
                                                                 (get_days_rented() > 1))
                                                                      {
                                                                         return 2;
                                                                      }
                                                                      else
                                                                      {
                                                                         return 1;
                                                                      }
                                                                   }
                                                                   ..
                                                                 }
// Customer.as                                                   // Customer.as

public function checkout ():String                               public function checkout ():String
{                                                                {
  ... while (rentals.length > 0)                                   ...
  {                                                                while (rentals.length > 0)
    var this_amount:Number = 0;                                    {
    var the_rental:Rental = rentals.shift() as Rental;               var this_amount:Number = 0;
                                                                     var the_rental:Rental = rentals.shift() as Rental;
    this_amount = amount_for(the_rental);
                                                                     this_amount = amount_for(the_rental);
    //
    bonus_points += 1;                                               //
                                                                     bonus_points += the_rental.get_bonus_points();
    //                   2    1
    if ((the_rental.get_movie().get_price_code() ==                  result += "-" + the_rental.get_movie().get_title() + " " +
Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1))        this_amount +" n";
    {                                                                total_amount += this_amount;
       bonus_points += 1;                                          }
    }                                                              ...
                                                                 }
    result += "-" + the_rental.get_movie().get_title() + " " +
this_amount +" n";                                              // Rental.as
    total_amount += this_amount;                                 public class Rental
  }                                                              {
  ...                                                              ..
}                                                                  public function get_bonus_points():int
                                                                   {
                                                                      //                  2     1
                                                                      if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&
                                                                 (get_days_rented() > 1))
                                                                      {
                                                                         return 2;
                                                                      }
                                                                      else
                                                                      {
                                                                         return 1;
                                                                      }
                                                                   }
                                                                   ..
                                                                 }
Replace Temp with Query
               ...
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ...                                                              public function checkout ():String
  public function checkout ():String                               {
  {                                                                  var total_amount:Number = 0;//
    var total_amount:Number = 0;//                                   var bonus_points:int = 0;//
    var bonus_points:int = 0;//                                      var rentals:Array = _rentals.concat();
    var rentals:Array = _rentals.concat();                           var result:String = get_name() +"            n";
    var result:String = get_name() +"            n";
                                                                         while (rentals.length > 0)
      while (rentals.length > 0)                                         {
      {                                                                    var the_rental:Rental = rentals.shift() as Rental;
        var the_rental:Rental = rentals.shift() as Rental;
                                                                           //
          //                                                               bonus_points += the_rental.get_bonus_points();
          bonus_points += the_rental.get_bonus_points();
                                                                       result += "-" + the_rental.get_movie().get_title() + " "
      result += "-" + the_rental.get_movie().get_title() + " "   + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n";                                    }
      total_amount += the_rental.get_charge();
    }                                                                    result += "n      " + get_total_charge() + "n";
                                                                         result += "        " + bonus_points + " ";
      result += "n        " + total_amount + "n";
      result += "          " + bonus_points + " ";                       return result;
                                                                     }
      return result;
    }                                                                private function get_total_charge():Number
    ...                                                              {
}                                                                      var rentals:Array = _rentals.concat();
                                                                       var result:Number = 0;
                                                                       while (rentals.length > 0)
                                                                       {
                                                                         var the_rental:Rental = rentals.shift() as Rental;
                                                                         result += the_rental.get_charge();
                                                                       }
                                                                       return result;
                                                                     }
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ...                                                              public function checkout ():String
  public function checkout ():String                               {
  {                                                                  var total_amount:Number = 0;//
    var total_amount:Number = 0;//                                   var bonus_points:int = 0;//
    var bonus_points:int = 0;//                                      var rentals:Array = _rentals.concat();
    var rentals:Array = _rentals.concat();                           var result:String = get_name() +"            n";
    var result:String = get_name() +"            n";
                                                                         while (rentals.length > 0)
      while (rentals.length > 0)                                         {
      {                                                                    var the_rental:Rental = rentals.shift() as Rental;
        var the_rental:Rental = rentals.shift() as Rental;
                                                                           //
          //                                                               bonus_points += the_rental.get_bonus_points();
          bonus_points += the_rental.get_bonus_points();
                                                                       result += "-" + the_rental.get_movie().get_title() + " "
      result += "-" + the_rental.get_movie().get_title() + " "   + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n";                                    }
      total_amount += the_rental.get_charge();
    }                                                                    result += "n      " + get_total_charge() + "n";
                                                                         result += "        " + bonus_points + " ";
      result += "n        " + total_amount + "n";
      result += "          " + bonus_points + " ";                       return result;
                                                                     }
      return result;
    }                                                                private function get_total_charge():Number
    ...                                                              {
}                                                                      var rentals:Array = _rentals.concat();
                                                                       var result:Number = 0;
                                                                       while (rentals.length > 0)
                                                                       {
                                                                         var the_rental:Rental = rentals.shift() as Rental;
                                                                         result += the_rental.get_charge();
                                                                       }
                                                                       return result;
                                                                     }
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ...                                                              public function checkout ():String
  public function checkout ():String                               {
  {                                                                  var total_amount:Number = 0;//
    var total_amount:Number = 0;//                                   var bonus_points:int = 0;//
    var bonus_points:int = 0;//                                      var rentals:Array = _rentals.concat();
    var rentals:Array = _rentals.concat();                           var result:String = get_name() +"            n";
    var result:String = get_name() +"            n";
                                                                         while (rentals.length > 0)
      while (rentals.length > 0)                                         {
      {                                                                    var the_rental:Rental = rentals.shift() as Rental;
        var the_rental:Rental = rentals.shift() as Rental;
                                                                           //
          //                                                               bonus_points += the_rental.get_bonus_points();
          bonus_points += the_rental.get_bonus_points();
                                                                       result += "-" + the_rental.get_movie().get_title() + " "
      result += "-" + the_rental.get_movie().get_title() + " "   + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n";                                    }
      total_amount += the_rental.get_charge();
    }                                                                    result += "n      " + get_total_charge() + "n";
                                                                         result += "        " + bonus_points + " ";
      result += "n        " + total_amount + "n";
      result += "          " + bonus_points + " ";                       return result;
                                                                     }
      return result;
    }                                                                private function get_total_charge():Number
    ...                                                              {
}                                                                      var rentals:Array = _rentals.concat();
                                                                       var result:Number = 0;
                                                                       while (rentals.length > 0)
                                                                       {
                                                                         var the_rental:Rental = rentals.shift() as Rental;
                                                                         result += the_rental.get_charge();
                                                                       }
                                                                       return result;
                                                                     }
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ...                                                              public function checkout ():String
  public function checkout ():String                               {
  {                                                                  var total_amount:Number = 0;//
    var total_amount:Number = 0;//                                   var bonus_points:int = 0;//
    var bonus_points:int = 0;//                                      var rentals:Array = _rentals.concat();
    var rentals:Array = _rentals.concat();                           var result:String = get_name() +"            n";
    var result:String = get_name() +"            n";
                                                                         while (rentals.length > 0)
      while (rentals.length > 0)                                         {
      {                                                                    var the_rental:Rental = rentals.shift() as Rental;
        var the_rental:Rental = rentals.shift() as Rental;
                                                                           //
          //                                                               bonus_points += the_rental.get_bonus_points();
          bonus_points += the_rental.get_bonus_points();
                                                                       result += "-" + the_rental.get_movie().get_title() + " "
      result += "-" + the_rental.get_movie().get_title() + " "   + the_rental.get_charge() +" n";
+ the_rental.get_charge() +" n";                                    }
      total_amount += the_rental.get_charge();
    }                                                                    result += "n      " + get_total_charge() + "n";
                                                                         result += "        " + bonus_points + " ";
      result += "n        " + total_amount + "n";
      result += "          " + bonus_points + " ";                       return result;
                                                                     }
      return result;
    }                                                                private function get_total_charge():Number
    ...                                                              {
}                                                                      var rentals:Array = _rentals.concat();
                                                                       var result:Number = 0;
                                                                       while (rentals.length > 0)
                                                                       {
                                                                         var the_rental:Rental = rentals.shift() as Rental;
                                                                         result += the_rental.get_charge();
                                                                       }
                                                                       return result;
                                                                     }
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ..                                                               ..
  public function checkout ():String                               public function checkout ():String
  {                                                                {
     var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
     var rentals:Array = _rentals.concat();                           var rentals:Array = _rentals.concat();
     var result:String = get_name() +"            n";                var result:String = get_name() +"           n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

           //                                                          result += "-" + the_rental.get_movie().get_title() + " "
           bonus_points += the_rental.get_bonus_points();        + the_rental.get_charge() +" n";
                                                                     }
      result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n";                                        result += "n      " + get_total_charge() + "n";
      total_amount += the_rental.get_charge();                           result += "        " + get_total_bonus_points() + "    ";
    }
                                                                         return result;
         result += "n      " + total_amount + "n";                 }
         result += "        " + bonus_points + " ";
                                                                     private function get_total_bonus_points():int
         return result;                                              {
    }                                                                   var rentals:Array = _rentals.concat();
    ..                                                                  var result:int = 0;
}                                                                       while (rentals.length > 0)
                                                                        {
                                                                          var the_rental:Rental = rentals.shift() as Rental;
                                                                          result += the_rental.get_bonus_points();
                                                                        }
                                                                        return result;
                                                                     }
                                                                     ..
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ..                                                               ..
  public function checkout ():String                               public function checkout ():String
  {                                                                {
     var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
     var rentals:Array = _rentals.concat();                           var rentals:Array = _rentals.concat();
     var result:String = get_name() +"            n";                var result:String = get_name() +"           n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

           //                                                          result += "-" + the_rental.get_movie().get_title() + " "
           bonus_points += the_rental.get_bonus_points();        + the_rental.get_charge() +" n";
                                                                     }
      result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n";                                        result += "n      " + get_total_charge() + "n";
      total_amount += the_rental.get_charge();                           result += "        " + get_total_bonus_points() + "    ";
    }
                                                                         return result;
         result += "n      " + total_amount + "n";                 }
         result += "        " + bonus_points + " ";
                                                                     private function get_total_bonus_points():int
         return result;                                              {
    }                                                                   var rentals:Array = _rentals.concat();
    ..                                                                  var result:int = 0;
}                                                                       while (rentals.length > 0)
                                                                        {
                                                                          var the_rental:Rental = rentals.shift() as Rental;
                                                                          result += the_rental.get_bonus_points();
                                                                        }
                                                                        return result;
                                                                     }
                                                                     ..
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ..                                                               ..
  public function checkout ():String                               public function checkout ():String
  {                                                                {
     var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
     var rentals:Array = _rentals.concat();                           var rentals:Array = _rentals.concat();
     var result:String = get_name() +"            n";                var result:String = get_name() +"           n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

           //                                                          result += "-" + the_rental.get_movie().get_title() + " "
           bonus_points += the_rental.get_bonus_points();        + the_rental.get_charge() +" n";
                                                                     }
      result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n";                                        result += "n      " + get_total_charge() + "n";
      total_amount += the_rental.get_charge();                           result += "        " + get_total_bonus_points() + "    ";
    }
                                                                         return result;
         result += "n      " + total_amount + "n";                 }
         result += "        " + bonus_points + " ";
                                                                     private function get_total_bonus_points():int
         return result;                                              {
    }                                                                   var rentals:Array = _rentals.concat();
    ..                                                                  var result:int = 0;
}                                                                       while (rentals.length > 0)
                                                                        {
                                                                          var the_rental:Rental = rentals.shift() as Rental;
                                                                          result += the_rental.get_bonus_points();
                                                                        }
                                                                        return result;
                                                                     }
                                                                     ..
                                                                 }
// Customer.as                                                   // Customer.as
public class Customer                                            public class Customer
{                                                                {
  ..                                                               ..
  public function checkout ():String                               public function checkout ():String
  {                                                                {
     var total_amount:Number = 0;//                                   var total_amount:Number = 0;//
     var bonus_points:int = 0;//                                      var bonus_points:int = 0;//
     var rentals:Array = _rentals.concat();                           var rentals:Array = _rentals.concat();
     var result:String = get_name() +"            n";                var result:String = get_name() +"           n";

         while (rentals.length > 0)                                      while (rentals.length > 0)
         {                                                               {
           var the_rental:Rental = rentals.shift() as Rental;              var the_rental:Rental = rentals.shift() as Rental;

           //                                                          result += "-" + the_rental.get_movie().get_title() + " "
           bonus_points += the_rental.get_bonus_points();        + the_rental.get_charge() +" n";
                                                                     }
      result += "-" + the_rental.get_movie().get_title() + " "
+ the_rental.get_charge() +" n";                                        result += "n      " + get_total_charge() + "n";
      total_amount += the_rental.get_charge();                           result += "        " + get_total_bonus_points() + "    ";
    }
                                                                         return result;
         result += "n      " + total_amount + "n";                 }
         result += "        " + bonus_points + " ";
                                                                     private function get_total_bonus_points():int
         return result;                                              {
    }                                                                   var rentals:Array = _rentals.concat();
    ..                                                                  var result:int = 0;
}                                                                       while (rentals.length > 0)
                                                                        {
                                                                          var the_rental:Rental = rentals.shift() as Rental;
                                                                          result += the_rental.get_bonus_points();
                                                                        }
                                                                        return result;
                                                                     }
                                                                     ..
                                                                 }
Move Method
      ...
// Rental.as                                                // Rental.as
public class Rental                                         public class Rental
{                                                           {
  ...                                                         public function get_charge():Number
  public function get_charge():Number                         {
  {                                                             return _movie.get_charge(_days_rented);
    var result:int = 0;                                       }
    switch (get_movie().get_price_code())                   }
    {
      case Movie.REGULAR ://                                // Movie.as
        result += 2;                                        public class Movie
        if (get_days_rented() > 2)                          {
        {                                                     public function get_charge(days_rented:int):Number
          result += (get_days_rented() - 2) * 1.5;            {
        }                                                       var result:int = 0;
        break;                                                  switch (get_price_code())
                                                                {
             case Movie.NEW_RELEASE ://                           case Movie.REGULAR ://
               result += get_days_rented() * 3;                     result += 2;
               break;                                               if (days_rented > 2)
                                                                    {
             case Movie.CHILDRENS ://                                 result += (days_rented - 2) * 1.5;
               result += 1.5;                                       }
               if (get_days_rented() > 3)                           break;
               {
                 result += (get_days_rented() - 3) * 1.5;               case Movie.NEW_RELEASE ://
               }                                                          result += days_rented * 3;
               break;                                                     break;
         }
                                                                        case Movie.CHILDRENS ://
         return result;                                                   result += 1.5;
    }                                                                     if (days_rented > 3)
    ..                                                                    {
}                                                                           result += (days_rented - 3) * 1.5;
                                                                          }
                                                                          break;
                                                                    }

                                                                    return result;
                                                                }
                                                            }
// Rental.as                                                // Rental.as
public class Rental                                         public class Rental
{                                                           {
  ...                                                         public function get_charge():Number
  public function get_charge():Number                         {
  {                                                             return _movie.get_charge(_days_rented);
    var result:int = 0;                                       }
    switch (get_movie().get_price_code())                   }
    {
      case Movie.REGULAR ://                                // Movie.as
        result += 2;                                        public class Movie
        if (get_days_rented() > 2)                          {
        {                                                     public function get_charge(days_rented:int):Number
          result += (get_days_rented() - 2) * 1.5;            {
        }                                                       var result:int = 0;
        break;                                                  switch (get_price_code())
                                                                {
             case Movie.NEW_RELEASE ://                           case Movie.REGULAR ://
               result += get_days_rented() * 3;                     result += 2;
               break;                                               if (days_rented > 2)
                                                                    {
             case Movie.CHILDRENS ://                                 result += (days_rented - 2) * 1.5;
               result += 1.5;                                       }
               if (get_days_rented() > 3)                           break;
               {
                 result += (get_days_rented() - 3) * 1.5;               case Movie.NEW_RELEASE ://
               }                                                          result += days_rented * 3;
               break;                                                     break;
         }
                                                                        case Movie.CHILDRENS ://
         return result;                                                   result += 1.5;
    }                                                                     if (days_rented > 3)
    ..                                                                    {
}                                                                           result += (days_rented - 3) * 1.5;
                                                                          }
                                                                          break;
                                                                    }

                                                                    return result;
                                                                }
                                                            }
// Rental.as                                                // Rental.as
public class Rental                                         public class Rental
{                                                           {
  ...                                                         public function get_charge():Number
  public function get_charge():Number                         {
  {                                                             return _movie.get_charge(_days_rented);
    var result:int = 0;                                       }
    switch (get_movie().get_price_code())                   }
    {
      case Movie.REGULAR ://                                // Movie.as
        result += 2;                                        public class Movie
        if (get_days_rented() > 2)                          {
        {                                                     public function get_charge(days_rented:int):Number
          result += (get_days_rented() - 2) * 1.5;            {
        }                                                       var result:int = 0;
        break;                                                  switch (get_price_code())
                                                                {
             case Movie.NEW_RELEASE ://                           case Movie.REGULAR ://
               result += get_days_rented() * 3;                     result += 2;
               break;                                               if (days_rented > 2)
                                                                    {
             case Movie.CHILDRENS ://                                 result += (days_rented - 2) * 1.5;
               result += 1.5;                                       }
               if (get_days_rented() > 3)                           break;
               {
                 result += (get_days_rented() - 3) * 1.5;               case Movie.NEW_RELEASE ://
               }                                                          result += days_rented * 3;
               break;                                                     break;
         }
                                                                        case Movie.CHILDRENS ://
         return result;                                                   result += 1.5;
    }                                                                     if (days_rented > 3)
    ..                                                                    {
}                                                                           result += (days_rented - 3) * 1.5;
                                                                          }
                                                                          break;
                                                                    }

                                                                    return result;
                                                                }
                                                            }
// Rental.as                                                // Rental.as
public class Rental                                         public class Rental
{                                                           {
  ...                                                         public function get_charge():Number
  public function get_charge():Number                         {
  {                                                             return _movie.get_charge(_days_rented);
    var result:int = 0;                                       }
    switch (get_movie().get_price_code())                   }
    {
      case Movie.REGULAR ://                                // Movie.as
        result += 2;                                        public class Movie
        if (get_days_rented() > 2)                          {
        {                                                     public function get_charge(days_rented:int):Number
          result += (get_days_rented() - 2) * 1.5;            {
        }                                                       var result:int = 0;
        break;                                                  switch (get_price_code())
                                                                {
             case Movie.NEW_RELEASE ://                           case Movie.REGULAR ://
               result += get_days_rented() * 3;                     result += 2;
               break;                                               if (days_rented > 2)
                                                                    {
             case Movie.CHILDRENS ://                                 result += (days_rented - 2) * 1.5;
               result += 1.5;                                       }
               if (get_days_rented() > 3)                           break;
               {
                 result += (get_days_rented() - 3) * 1.5;               case Movie.NEW_RELEASE ://
               }                                                          result += days_rented * 3;
               break;                                                     break;
         }
                                                                        case Movie.CHILDRENS ://
         return result;                                                   result += 1.5;
    }                                                                     if (days_rented > 3)
    ..                                                                    {
}                                                                           result += (days_rented - 3) * 1.5;
                                                                          }
                                                                          break;
                                                                    }

                                                                    return result;
                                                                }
                                                            }
// Rental.as                                                      // Rental.as
public class Rental                                               public class Rental
{                                                                 {
  ...                                                               ..
  public function get_bonus_points():int                            public function get_charge():Number
  {                                                                 {
     //                  2     1                                       return _movie.get_bonus_points(_days_rented);
     if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&     }
(get_days_rented() > 1))                                            ..
     {                                                            }
        return 2;
     }                                                            // Movie.as
     else                                                         public class Movie
     {                                                            {
        return 1;                                                   ..
     }                                                              public function get_bonus_points(days_rented:int):int
  }                                                                 {
  ..                                                                   //                  2     1
}                                                                      if ((get_price_code() == Movie.NEW_RELEASE) && (days_rented
                                                                  > 1))
                                                                       {
                                                                          return 2;
                                                                       }
                                                                       else
                                                                       {
                                                                          return 1;
                                                                       }
                                                                    }
                                                                    ..
                                                                  }
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
Refactoring in AS3
1 of 99

Recommended

Decorated Attribute Grammars (CC 2009) by
Decorated Attribute Grammars (CC 2009)Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)lennartkats
680 views29 slides
Brief Summary Of C++ by
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++Haris Lye
1.2K views6 slides
Pitfalls In Aspect Mining by
Pitfalls In Aspect MiningPitfalls In Aspect Mining
Pitfalls In Aspect Miningkim.mens
502 views19 slides
Voce Tem Orgulho Do Seu Codigo by
Voce Tem Orgulho Do Seu CodigoVoce Tem Orgulho Do Seu Codigo
Voce Tem Orgulho Do Seu CodigoVictor Hugo Germano
801 views89 slides
Eclipse Banking Day by
Eclipse Banking DayEclipse Banking Day
Eclipse Banking DaySven Efftinge
890 views65 slides
Design pattern - part 3 by
Design pattern - part 3Design pattern - part 3
Design pattern - part 3Jieyi Wu
111 views56 slides

More Related Content

What's hot

Design of bare metal proxy compute node by
Design of bare metal proxy compute nodeDesign of bare metal proxy compute node
Design of bare metal proxy compute nodeLorin Hochstein
4.5K views9 slides
[1062BPY12001] Data analysis with R / week 2 by
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
158 views33 slides
Mathcentre basic differentiation by
Mathcentre basic differentiationMathcentre basic differentiation
Mathcentre basic differentiationapwazap777
1.3K views29 slides
Advanced python by
Advanced pythonAdvanced python
Advanced pythonEU Edge
805 views22 slides
Mattbrenner by
MattbrennerMattbrenner
MattbrennerDroidcon Berlin
824 views19 slides
The Chain Rule Powerpoint Lesson by
The Chain Rule Powerpoint LessonThe Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint LessonPaul Hawks
2.9K views10 slides

What's hot(17)

Design of bare metal proxy compute node by Lorin Hochstein
Design of bare metal proxy compute nodeDesign of bare metal proxy compute node
Design of bare metal proxy compute node
Lorin Hochstein4.5K views
Mathcentre basic differentiation by apwazap777
Mathcentre basic differentiationMathcentre basic differentiation
Mathcentre basic differentiation
apwazap7771.3K views
Advanced python by EU Edge
Advanced pythonAdvanced python
Advanced python
EU Edge805 views
The Chain Rule Powerpoint Lesson by Paul Hawks
The Chain Rule Powerpoint LessonThe Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint Lesson
Paul Hawks2.9K views
Design pattern - part 1 by Jieyi Wu
Design pattern - part 1Design pattern - part 1
Design pattern - part 1
Jieyi Wu349 views
Lesson 22: Optimization I (Section 10 Version) by Matthew Leingang
Lesson 22: Optimization I (Section 10 Version)Lesson 22: Optimization I (Section 10 Version)
Lesson 22: Optimization I (Section 10 Version)
Matthew Leingang381 views
Lesson 22: Optimization I (Section 4 version) by Matthew Leingang
Lesson 22: Optimization I (Section 4 version)Lesson 22: Optimization I (Section 4 version)
Lesson 22: Optimization I (Section 4 version)
Matthew Leingang375 views
Deep learning with C++ - an introduction to tiny-dnn by Taiga Nomi
Deep learning with C++  - an introduction to tiny-dnnDeep learning with C++  - an introduction to tiny-dnn
Deep learning with C++ - an introduction to tiny-dnn
Taiga Nomi13.4K views
Dynamic programming burglar_problem by Russell Childs
Dynamic programming burglar_problemDynamic programming burglar_problem
Dynamic programming burglar_problem
Russell Childs143 views
Introduction à dart by yohanbeschi
Introduction à dartIntroduction à dart
Introduction à dart
yohanbeschi486 views
Summary of "A Universally-Truthful Approximation Scheme for Multi-unit Auction" by Thatchaphol Saranurak
Summary of "A Universally-Truthful Approximation Scheme for Multi-unit Auction"Summary of "A Universally-Truthful Approximation Scheme for Multi-unit Auction"
Summary of "A Universally-Truthful Approximation Scheme for Multi-unit Auction"
3장 자동적으로 움직이는 게임 에이전트 생성법_2 by suitzero
3장 자동적으로 움직이는 게임 에이전트 생성법_23장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_2
suitzero471 views
Class 21: Changing State by David Evans
Class 21: Changing StateClass 21: Changing State
Class 21: Changing State
David Evans574 views
Explanation on Tensorflow example -Deep mnist for expert by 홍배 김
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert
홍배 김7.7K views

Similar to Refactoring in AS3

Refactoring Example by
Refactoring ExampleRefactoring Example
Refactoring Exampleliufabin 66688
553 views54 slides
Android Refactoring by
Android RefactoringAndroid Refactoring
Android RefactoringGodfrey Nolan
1.4K views53 slides
Refactoring Simple Example by
Refactoring Simple ExampleRefactoring Simple Example
Refactoring Simple Exampleliufabin 66688
402 views16 slides
SANER 2019 Most Influential Paper Talk by
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkNikolaos Tsantalis
125 views50 slides
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx by
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docxSimple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docxbudabrooks46239
4 views52 slides
Code Generation in PHP - PHPConf 2015 by
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
2.4K views108 slides

Similar to Refactoring in AS3(20)

Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx by budabrooks46239
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docxSimple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx
budabrooks462394 views
Code Generation in PHP - PHPConf 2015 by Lin Yo-An
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An2.4K views
Java Patterns - Strategy by Paul Blundell
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - Strategy
Paul Blundell572 views
The Promised Land (in Angular) by Domenic Denicola
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
Domenic Denicola23.1K views
$q and Promises in AngularJS by a_sharif
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
a_sharif6.1K views
重構—改善既有程式的設計(chapter 9) by Chris Huang
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
Chris Huang625 views
Gearmam, from the_worker's_perspective copy by Brian Aker
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
Brian Aker1.1K views
Gearmam, from the_worker's_perspective copy by Brian Aker
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
Brian Aker730 views
slides by thamerr
slidesslides
slides
thamerr190 views
Ten useful JavaScript tips & best practices by Ankit Rastogi
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
Ankit Rastogi3.5K views
Converting Db Schema Into Uml Classes by Kaniska Mandal
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
Kaniska Mandal1K views
How Kris Writes Symfony Apps by Kris Wallsmith
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
Kris Wallsmith17.1K views
Create a Customized GMF DnD Framework by Kaniska Mandal
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
Kaniska Mandal969 views
CQRS and Event Sourcing in a Symfony application by Samuel ROZE
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
Samuel ROZE12.7K views

More from Eddie Kao

Rails girls in Taipei by
Rails girls in TaipeiRails girls in Taipei
Rails girls in TaipeiEddie Kao
897 views13 slides
Rails Girls in Taipei by
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in TaipeiEddie Kao
2.6K views54 slides
Let's Learn Ruby - Basic by
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
3.2K views165 slides
iOS app development and Open Source by
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open SourceEddie Kao
1.2K views38 slides
Vim by
VimVim
VimEddie Kao
1.7K views99 slides
from Ruby to Objective-C by
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-CEddie Kao
1.4K views95 slides

More from Eddie Kao(20)

Rails girls in Taipei by Eddie Kao
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
Eddie Kao897 views
Rails Girls in Taipei by Eddie Kao
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
Eddie Kao2.6K views
Let's Learn Ruby - Basic by Eddie Kao
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
Eddie Kao3.2K views
iOS app development and Open Source by Eddie Kao
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open Source
Eddie Kao1.2K views
from Ruby to Objective-C by Eddie Kao
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
Eddie Kao1.4K views
Code Reading by Eddie Kao
Code ReadingCode Reading
Code Reading
Eddie Kao637 views
CreateJS - from Flash to Javascript by Eddie Kao
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to Javascript
Eddie Kao2.3K views
May the source_be_with_you by Eddie Kao
May the source_be_with_youMay the source_be_with_you
May the source_be_with_you
Eddie Kao614 views
Why I use Vim by Eddie Kao
Why I use VimWhy I use Vim
Why I use Vim
Eddie Kao680 views
There is something about Event by Eddie Kao
There is something about EventThere is something about Event
There is something about Event
Eddie Kao573 views
Flash Ecosystem and Open Source by Eddie Kao
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open Source
Eddie Kao444 views
Happy Programming with CoffeeScript by Eddie Kao
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
Eddie Kao11K views
Ruby without rails by Eddie Kao
Ruby without railsRuby without rails
Ruby without rails
Eddie Kao1.2K views
CoffeeScript-Ruby-Tuesday by Eddie Kao
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
Eddie Kao1.6K views
CoffeeScript by Eddie Kao
CoffeeScriptCoffeeScript
CoffeeScript
Eddie Kao1.2K views
API Design by Eddie Kao
API DesignAPI Design
API Design
Eddie Kao2.8K views
3rd AS Study Group by Eddie Kao
3rd AS Study Group3rd AS Study Group
3rd AS Study Group
Eddie Kao393 views
iOS Game Development with Cocos2d by Eddie Kao
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
Eddie Kao1.8K views

Recently uploaded

Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...NUS-ISS
34 views35 slides
Melek BEN MAHMOUD.pdf by
Melek BEN MAHMOUD.pdfMelek BEN MAHMOUD.pdf
Melek BEN MAHMOUD.pdfMelekBenMahmoud
14 views1 slide
STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
12 views1 slide
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
73 views25 slides
Combining Orchestration and Choreography for a Clean Architecture by
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean ArchitectureThomasHeinrichs1
69 views24 slides
Perth MeetUp November 2023 by
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023 Michael Price
15 views44 slides

Recently uploaded(20)

Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
.conf Go 2023 - Data analysis as a routine by Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk93 views
Spesifikasi Lengkap ASUS Vivobook Go 14 by Dot Semarang
Spesifikasi Lengkap ASUS Vivobook Go 14Spesifikasi Lengkap ASUS Vivobook Go 14
Spesifikasi Lengkap ASUS Vivobook Go 14
Dot Semarang35 views
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk88 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS27 views
DALI Basics Course 2023 by Ivory Egg
DALI Basics Course  2023DALI Basics Course  2023
DALI Basics Course 2023
Ivory Egg14 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views

Refactoring in AS3

  • 4. AS3 OOP Design Pattern
  • 5. ...
  • 7. B
  • 8. !?
  • 9. ?
  • 10. !=
  • 11. ?
  • 12. ?
  • 13. ?
  • 14. duplicated code, long method, large class, long parameter list...
  • 15. If it stinks, change it.
  • 16. Rule of Three Three strikes and you refactor
  • 17. ?
  • 18. ? ! ...
  • 19. ? ... !
  • 20. ? ... !
  • 21. Design Pattern (over-engineering)
  • 22. Design Pattern v.s. Refactoring
  • 24. !
  • 25. &
  • 26. !
  • 27. .. 1. 2. 3. 2 2 2 1.5 1.5 3 3 1.5 3 1 1 1
  • 29. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 30. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 31. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 32. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 34. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 35. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 36. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 37. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 38. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = the_rental.get_charge(); // // bonus_points += 1; bonus_points += 1; ... ... } } result += "n " + total_amount + "n"; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; result += " " + bonus_points + " "; return result; return result; } } .. .. } }
  • 39. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = the_rental.get_charge(); // // bonus_points += 1; bonus_points += 1; ... ... } } result += "n " + total_amount + "n"; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; result += " " + bonus_points + " "; return result; return result; } } .. .. } }
  • 40. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = the_rental.get_charge(); // // bonus_points += 1; bonus_points += 1; ... ... } } result += "n " + total_amount + "n"; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; result += " " + bonus_points + " "; return result; return result; } } .. .. } }
  • 41. Replace Temp with Query ...
  • 42. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // this_amount = amount_for(the_rental); bonus_points += 1; // // 2 1 bonus_points += 1; if ((the_rental.get_movie().get_price_code() == Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) // 2 1 { if ((the_rental.get_movie().get_price_code() == bonus_points += 1; Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) } { result += "-" + the_rental.get_movie().get_title() + " " + bonus_points += 1; the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); result += "-" + the_rental.get_movie().get_title() + " " + } this_amount +" n"; total_amount += this_amount; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; result += "n " + total_amount + "n"; return result; result += " " + bonus_points + " "; } return result; }
  • 43. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // this_amount = amount_for(the_rental); bonus_points += 1; // // 2 1 bonus_points += 1; if ((the_rental.get_movie().get_price_code() == Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) // 2 1 { if ((the_rental.get_movie().get_price_code() == bonus_points += 1; Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) } { result += "-" + the_rental.get_movie().get_title() + " " + bonus_points += 1; the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); result += "-" + the_rental.get_movie().get_title() + " " + } this_amount +" n"; total_amount += this_amount; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; result += "n " + total_amount + "n"; return result; result += " " + bonus_points + " "; } return result; }
  • 44. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // this_amount = amount_for(the_rental); bonus_points += 1; // // 2 1 bonus_points += 1; if ((the_rental.get_movie().get_price_code() == Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) // 2 1 { if ((the_rental.get_movie().get_price_code() == bonus_points += 1; Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) } { result += "-" + the_rental.get_movie().get_title() + " " + bonus_points += 1; the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); result += "-" + the_rental.get_movie().get_title() + " " + } this_amount +" n"; total_amount += this_amount; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; result += "n " + total_amount + "n"; return result; result += " " + bonus_points + " "; } return result; }
  • 46. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 47. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 48. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 49. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 50. Replace Temp with Query ...
  • 51. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 52. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 53. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 54. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 55. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 56. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 57. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 58. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 59. Move Method ...
  • 60. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 61. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 62. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 63. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 64. // Rental.as // Rental.as public class Rental public class Rental { { ... .. public function get_bonus_points():int public function get_charge():Number { { // 2 1 return _movie.get_bonus_points(_days_rented); if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && } (get_days_rented() > 1)) .. { } return 2; } // Movie.as else public class Movie { { return 1; .. } public function get_bonus_points(days_rented:int):int } { .. // 2 1 } if ((get_price_code() == Movie.NEW_RELEASE) && (days_rented > 1)) { return 2; } else { return 1; } } .. }