SlideShare a Scribd company logo
1 of 99
Refactoring in AS3
http://blog.eddie.com.tw
aquarianboy@ptt
eddie@adcube.com.tw
aquarianboy@plurk
eddiekao@facebook
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
!
&
!
..


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

More Related Content

What's hot

Design of bare metal proxy compute node
Design of bare metal proxy compute nodeDesign of bare metal proxy compute node
Design of bare metal proxy compute nodeLorin Hochstein
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
 
Mathcentre basic differentiation
Mathcentre basic differentiationMathcentre basic differentiation
Mathcentre basic differentiationapwazap777
 
Advanced python
Advanced pythonAdvanced python
Advanced pythonEU Edge
 
The Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint LessonThe Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint LessonPaul Hawks
 
Design pattern - part 1
Design pattern - part 1Design pattern - part 1
Design pattern - part 1Jieyi Wu
 
Lesson 22: Optimization I (Section 10 Version)
Lesson 22: Optimization I (Section 10 Version)Lesson 22: Optimization I (Section 10 Version)
Lesson 22: Optimization I (Section 10 Version)Matthew Leingang
 
Lesson 22: Optimization I (Section 4 version)
Lesson 22: Optimization I (Section 4 version)Lesson 22: Optimization I (Section 4 version)
Lesson 22: Optimization I (Section 4 version)Matthew Leingang
 
Deep learning with C++ - an introduction to tiny-dnn
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-dnnTaiga Nomi
 
Dynamic programming burglar_problem
Dynamic programming burglar_problemDynamic programming burglar_problem
Dynamic programming burglar_problemRussell Childs
 
Introduction à dart
Introduction à dartIntroduction à dart
Introduction à dartyohanbeschi
 
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"
Summary of "A Universally-Truthful Approximation Scheme for Multi-unit Auction"Thatchaphol Saranurak
 
3장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_23장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_2suitzero
 
Class 21: Changing State
Class 21: Changing StateClass 21: Changing State
Class 21: Changing StateDavid Evans
 
Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert홍배 김
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationJacopo Mangiavacchi
 

What's hot (17)

Design of bare metal proxy compute node
Design of bare metal proxy compute nodeDesign of bare metal proxy compute node
Design of bare metal proxy compute node
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
Mathcentre basic differentiation
Mathcentre basic differentiationMathcentre basic differentiation
Mathcentre basic differentiation
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 
Mattbrenner
MattbrennerMattbrenner
Mattbrenner
 
The Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint LessonThe Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint Lesson
 
Design pattern - part 1
Design pattern - part 1Design pattern - part 1
Design pattern - part 1
 
Lesson 22: Optimization I (Section 10 Version)
Lesson 22: Optimization I (Section 10 Version)Lesson 22: Optimization I (Section 10 Version)
Lesson 22: Optimization I (Section 10 Version)
 
Lesson 22: Optimization I (Section 4 version)
Lesson 22: Optimization I (Section 4 version)Lesson 22: Optimization I (Section 4 version)
Lesson 22: Optimization I (Section 4 version)
 
Deep learning with C++ - an introduction to tiny-dnn
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
 
Dynamic programming burglar_problem
Dynamic programming burglar_problemDynamic programming burglar_problem
Dynamic programming burglar_problem
 
Introduction à dart
Introduction à dartIntroduction à dart
Introduction à dart
 
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"
Summary of "A Universally-Truthful Approximation Scheme for Multi-unit Auction"
 
3장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_23장 자동적으로 움직이는 게임 에이전트 생성법_2
3장 자동적으로 움직이는 게임 에이전트 생성법_2
 
Class 21: Changing State
Class 21: Changing StateClass 21: Changing State
Class 21: Changing State
 
Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert
 
Swift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML PersonalizationSwift for TensorFlow - CoreML Personalization
Swift for TensorFlow - CoreML Personalization
 

Similar to Refactoring in AS3

SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkNikolaos Tsantalis
 
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx
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
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - StrategyPaul Blundell
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)Domenic Denicola
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS a_sharif
 
The following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdfThe following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdf4babies2010
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)Chris Huang
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyBrian Aker
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesKaniska Mandal
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkKaniska Mandal
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationSamuel ROZE
 

Similar to Refactoring in AS3 (20)

Refactoring Example
Refactoring ExampleRefactoring Example
Refactoring Example
 
Android Refactoring
Android RefactoringAndroid Refactoring
Android Refactoring
 
SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper Talk
 
Simple Commsion Calculationbuild.xmlBuilds, tests, and runs t.docx
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
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - Strategy
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
 
The following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdfThe following is the (incomplete) header file for the class Fracti.pdf
The following is the (incomplete) header file for the class Fracti.pdf
 
J slider
J sliderJ slider
J slider
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
Gearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copyGearmam, from the_worker's_perspective copy
Gearmam, from the_worker's_perspective copy
 
slides
slidesslides
slides
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 

More from Eddie Kao

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in TaipeiEddie Kao
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in TaipeiEddie Kao
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open SourceEddie Kao
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-CEddie Kao
 
Code Reading
Code ReadingCode Reading
Code ReadingEddie Kao
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptEddie Kao
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_youEddie Kao
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use VimEddie Kao
 
There is something about Event
There is something about EventThere is something about Event
There is something about EventEddie Kao
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open SourceEddie Kao
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScriptEddie Kao
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without railsEddie Kao
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayEddie Kao
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptEddie Kao
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study GroupEddie Kao
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2dEddie Kao
 

More from Eddie Kao (20)

Rails girls in Taipei
Rails girls in TaipeiRails girls in Taipei
Rails girls in Taipei
 
Rails Girls in Taipei
Rails Girls in TaipeiRails Girls in Taipei
Rails Girls in Taipei
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
iOS app development and Open Source
iOS app development and Open SourceiOS app development and Open Source
iOS app development and Open Source
 
Vim
VimVim
Vim
 
from Ruby to Objective-C
from Ruby to Objective-Cfrom Ruby to Objective-C
from Ruby to Objective-C
 
Code Reading
Code ReadingCode Reading
Code Reading
 
CreateJS - from Flash to Javascript
CreateJS - from Flash to JavascriptCreateJS - from Flash to Javascript
CreateJS - from Flash to Javascript
 
May the source_be_with_you
May the source_be_with_youMay the source_be_with_you
May the source_be_with_you
 
Why I use Vim
Why I use VimWhy I use Vim
Why I use Vim
 
There is something about Event
There is something about EventThere is something about Event
There is something about Event
 
Flash Ecosystem and Open Source
Flash Ecosystem and Open SourceFlash Ecosystem and Open Source
Flash Ecosystem and Open Source
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
 
Ruby without rails
Ruby without railsRuby without rails
Ruby without rails
 
CoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-TuesdayCoffeeScript-Ruby-Tuesday
CoffeeScript-Ruby-Tuesday
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
API Design
API DesignAPI Design
API Design
 
測試
測試測試
測試
 
3rd AS Study Group
3rd AS Study Group3rd AS Study Group
3rd AS Study Group
 
iOS Game Development with Cocos2d
iOS Game Development with Cocos2diOS Game Development with Cocos2d
iOS Game Development with Cocos2d
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Refactoring in AS3

  • 3.
  • 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
  • 23.
  • 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; } } .. }