SlideShare a Scribd company logo
Refactoring in AS3
http://blog.eddie.com.tw
aquarianboy@ptt
eddie@adcube.com.tw
aquarianboy@plurk
eddiekao@facebook
Refactoring in AS3
AS3   OOP   Design Pattern
...
Refactoring...?
B
!?
?
!=
?
?
?
duplicated code, long method, large class, long parameter list...
If it stinks, change it.
Rule of Three
Three strikes and you refactor
?
?

    !
        ...
?
    ...


          !
?
    ...


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


1.
2.
3.



           2   2   2           1.5
         1.5   3   3           1.5
                           3



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                    return result;
                                                                }
                                                            }
// Rental.as                                                      // Rental.as
public class Rental                                               public class Rental
{                                                                 {
  ...                                                               ..
  public function get_bonus_points():int                            public function get_charge():Number
  {                                                                 {
     //                  2     1                                       return _movie.get_bonus_points(_days_rented);
     if ((get_movie().get_price_code() == Movie.NEW_RELEASE) &&     }
(get_days_rented() > 1))                                            ..
     {                                                            }
        return 2;
     }                                                            // Movie.as
     else                                                         public class Movie
     {                                                            {
        return 1;                                                   ..
     }                                                              public function get_bonus_points(days_rented:int):int
  }                                                                 {
  ..                                                                   //                  2     1
}                                                                      if ((get_price_code() == Movie.NEW_RELEASE) && (days_rented
                                                                  > 1))
                                                                       {
                                                                          return 2;
                                                                       }
                                                                       else
                                                                       {
                                                                          return 1;
                                                                       }
                                                                    }
                                                                    ..
                                                                  }
// 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;
                                                                       }
                                                                    }
                                                                    ..
                                                                  }
// 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;
                                                                       }
                                                                    }
                                                                    ..
                                                                  }
// 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;
                                                                       }
                                                                    }
                                                                    ..
                                                                  }
Self Encapsulate Field
// Movie.as                                                    // Movie.as
public class Movie                                             public class Movie
{                                                              {
  ...                                                            ...
  private var _title:String;//                                   private var _title:String;//
  private var _price_code:int;//                                 private var _price_code:int;//

    public function Movie (title:String,price_code:int):void       public function Movie (title:String,price_code:int):void
    {                                                              {
      _title = title;                                                _title = title;
      _price_code = price_code;                                      set_price_code(price_code);
    }                                                              }
    ...                                                            ...
}                                                              }
// Movie.as                                                    // Movie.as
public class Movie                                             public class Movie
{                                                              {
  ...                                                            ...
  private var _title:String;//                                   private var _title:String;//
  private var _price_code:int;//                                 private var _price_code:int;//

    public function Movie (title:String,price_code:int):void       public function Movie (title:String,price_code:int):void
    {                                                              {
      _title = title;                                                _title = title;
      _price_code = price_code;                                      set_price_code(price_code);
    }                                                              }
    ...                                                            ...
}                                                              }
// Movie.as                                                    // Movie.as
public class Movie                                             public class Movie
{                                                              {
  ...                                                            ...
  private var _title:String;//                                   private var _title:String;//
  private var _price_code:int;//                                 private var _price_code:int;//

    public function Movie (title:String,price_code:int):void       public function Movie (title:String,price_code:int):void
    {                                                              {
      _title = title;                                                _title = title;
      _price_code = price_code;                                      set_price_code(price_code);
    }                                                              }
    ...                                                            ...
}                                                              }
Inheritance
// Price.as                                      // RegularPrice.as
public class Price                               public class RegularPrice extends Price
{                                                {
  public function get_price_code():int             override public function get_price_code():int
  {                                                {
    throw new Error("method must be overrided:       return Movie.REGULAR;
get_price_code");                                  }
  }                                              }
}
                                                 // NewReleasePrice.as
                                                 public class NewReleasePrice extends Price
                                                 {
                                                   override public function get_price_code():int
                                                   {
                                                     return Movie.NEW_RELEASE;
                                                   }
                                                 }

                                                 // ChildrensPrice.as
                                                 public class ChildrensPrice extends Price
                                                 {
                                                   override public function get_price_code():int
                                                   {
                                                     return Movie.CHILDRENS;
                                                   }
                                                 }
// Price.as                                      // RegularPrice.as
public class Price                               public class RegularPrice extends Price
{                                                {
  public function get_price_code():int             override public function get_price_code():int
  {                                                {
    throw new Error("method must be overrided:       return Movie.REGULAR;
get_price_code");                                  }
  }                                              }
}
                                                 // NewReleasePrice.as
                                                 public class NewReleasePrice extends Price
                                                 {
                                                   override public function get_price_code():int
                                                   {
                                                     return Movie.NEW_RELEASE;
                                                   }
                                                 }

                                                 // ChildrensPrice.as
                                                 public class ChildrensPrice extends Price
                                                 {
                                                   override public function get_price_code():int
                                                   {
                                                     return Movie.CHILDRENS;
                                                   }
                                                 }
// Price.as                                      // RegularPrice.as
public class Price                               public class RegularPrice extends Price
{                                                {
  public function get_price_code():int             override public function get_price_code():int
  {                                                {
    throw new Error("method must be overrided:       return Movie.REGULAR;
get_price_code");                                  }
  }                                              }
}
                                                 // NewReleasePrice.as
                                                 public class NewReleasePrice extends Price
                                                 {
                                                   override public function get_price_code():int
                                                   {
                                                     return Movie.NEW_RELEASE;
                                                   }
                                                 }

                                                 // ChildrensPrice.as
                                                 public class ChildrensPrice extends Price
                                                 {
                                                   override public function get_price_code():int
                                                   {
                                                     return Movie.CHILDRENS;
                                                   }
                                                 }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
// Movie.as                                         // Movie.as
public class Movie                                  public class Movie
{                                                   {
  ...                                                 ...
  private var _title:String;      //                  private var _title:String; //
  private var _price_code:int;    //                  private var _price:Price; //

    public function get_price_code ():int               public function get_price_code ():int
    {                                                   {
      return _price_code;                                 return _price.get_price_code();
    }                                                   }

    public function set_price_code (arg:int):void       public function set_price_code (arg:int):void
    {                                                   {
       _price_code = arg;                                  switch(arg)
    }                                                      {
    ..                                                       case REGULAR:
}                                                              _price = new RegularPrice();
                                                               break;
                                                             case NEW_RELEASE:
                                                               _price = new NewReleasePrice();
                                                               break;
                                                             case CHILDRENS:
                                                               _price = new ChildrensPrice();
                                                               break;
                                                             default:
                                                               throw new Error("wrong price code");
                                                           }
                                                        }
                                                        ..
                                                    }
Move Method
      ...
// Movie.as                                             // Movie.as
public class Movie                                      public class Movie
{                                                       {
  ...                                                     public function get_charge (days_rented:int):Number
  public function get_charge (days_rented:int):Number     {
  {                                                         return _price.get_charge(days_rented);
    var result:int=0;                                     }
    switch (get_price_code())                           }
    {
      case Movie.REGULAR ://                            // Price.as
        result+= 2;                                     public class Price
        if (days_rented > 2)                            {
        {                                                 ..
          result+= days_rented - 2 * 1.5;                 public function get_charge (days_rented:int):Number
        }                                                 {
        break;                                               var result:int=0;
                                                             switch (get_price_code())
           case Movie.NEW_RELEASE ://                        {
             result+= days_rented * 3;                         case Movie.REGULAR ://
             break;                                              result+= 2;
                                                                 if (days_rented > 2)
           case Movie.CHILDRENS ://                              {
             result+= 1.5;                                         result+= days_rented - 2 * 1.5;
             if (days_rented > 3)                                }
             {                                                   break;
               result+= days_rented - 3 * 1.5;
             }                                                     case Movie.NEW_RELEASE ://
             break;                                                  result+= days_rented * 3;
         }                                                           break;
         return result;
    }                                                              case Movie.CHILDRENS ://
    ..                                                               result+= 1.5;
}                                                                    if (days_rented > 3)
                                                                     {
                                                                       result+= days_rented - 3 * 1.5;
                                                                     }
                                                                     break;
                                                                 }
                                                                 return result;
                                                            }
                                                            ..
                                                        }
// Movie.as                                             // Movie.as
public class Movie                                      public class Movie
{                                                       {
  ...                                                     public function get_charge (days_rented:int):Number
  public function get_charge (days_rented:int):Number     {
  {                                                         return _price.get_charge(days_rented);
    var result:int=0;                                     }
    switch (get_price_code())                           }
    {
      case Movie.REGULAR ://                            // Price.as
        result+= 2;                                     public class Price
        if (days_rented > 2)                            {
        {                                                 ..
          result+= days_rented - 2 * 1.5;                 public function get_charge (days_rented:int):Number
        }                                                 {
        break;                                               var result:int=0;
                                                             switch (get_price_code())
           case Movie.NEW_RELEASE ://                        {
             result+= days_rented * 3;                         case Movie.REGULAR ://
             break;                                              result+= 2;
                                                                 if (days_rented > 2)
           case Movie.CHILDRENS ://                              {
             result+= 1.5;                                         result+= days_rented - 2 * 1.5;
             if (days_rented > 3)                                }
             {                                                   break;
               result+= days_rented - 3 * 1.5;
             }                                                     case Movie.NEW_RELEASE ://
             break;                                                  result+= days_rented * 3;
         }                                                           break;
         return result;
    }                                                              case Movie.CHILDRENS ://
    ..                                                               result+= 1.5;
}                                                                    if (days_rented > 3)
                                                                     {
                                                                       result+= days_rented - 3 * 1.5;
                                                                     }
                                                                     break;
                                                                 }
                                                                 return result;
                                                            }
                                                            ..
                                                        }
// Movie.as                                             // Movie.as
public class Movie                                      public class Movie
{                                                       {
  ...                                                     public function get_charge (days_rented:int):Number
  public function get_charge (days_rented:int):Number     {
  {                                                         return _price.get_charge(days_rented);
    var result:int=0;                                     }
    switch (get_price_code())                           }
    {
      case Movie.REGULAR ://                            // Price.as
        result+= 2;                                     public class Price
        if (days_rented > 2)                            {
        {                                                 ..
          result+= days_rented - 2 * 1.5;                 public function get_charge (days_rented:int):Number
        }                                                 {
        break;                                               var result:int=0;
                                                             switch (get_price_code())
           case Movie.NEW_RELEASE ://                        {
             result+= days_rented * 3;                         case Movie.REGULAR ://
             break;                                              result+= 2;
                                                                 if (days_rented > 2)
           case Movie.CHILDRENS ://                              {
             result+= 1.5;                                         result+= days_rented - 2 * 1.5;
             if (days_rented > 3)                                }
             {                                                   break;
               result+= days_rented - 3 * 1.5;
             }                                                     case Movie.NEW_RELEASE ://
             break;                                                  result+= days_rented * 3;
         }                                                           break;
         return result;
    }                                                              case Movie.CHILDRENS ://
    ..                                                               result+= 1.5;
}                                                                    if (days_rented > 3)
                                                                     {
                                                                       result+= days_rented - 3 * 1.5;
                                                                     }
                                                                     break;
                                                                 }
                                                                 return result;
                                                            }
                                                            ..
                                                        }
// Movie.as                                             // Movie.as
public class Movie                                      public class Movie
{                                                       {
  ...                                                     public function get_charge (days_rented:int):Number
  public function get_charge (days_rented:int):Number     {
  {                                                         return _price.get_charge(days_rented);
    var result:int=0;                                     }
    switch (get_price_code())                           }
    {
      case Movie.REGULAR ://                            // Price.as
        result+= 2;                                     public class Price
        if (days_rented > 2)                            {
        {                                                 ..
          result+= days_rented - 2 * 1.5;                 public function get_charge (days_rented:int):Number
        }                                                 {
        break;                                               var result:int=0;
                                                             switch (get_price_code())
           case Movie.NEW_RELEASE ://                        {
             result+= days_rented * 3;                         case Movie.REGULAR ://
             break;                                              result+= 2;
                                                                 if (days_rented > 2)
           case Movie.CHILDRENS ://                              {
             result+= 1.5;                                         result+= days_rented - 2 * 1.5;
             if (days_rented > 3)                                }
             {                                                   break;
               result+= days_rented - 3 * 1.5;
             }                                                     case Movie.NEW_RELEASE ://
             break;                                                  result+= days_rented * 3;
         }                                                           break;
         return result;
    }                                                              case Movie.CHILDRENS ://
    ..                                                               result+= 1.5;
}                                                                    if (days_rented > 3)
                                                                     {
                                                                       result+= days_rented - 3 * 1.5;
                                                                     }
                                                                     break;
                                                                 }
                                                                 return result;
                                                            }
                                                            ..
                                                        }
Replace Conditional with Polymorphism
// Price.as                                               // RegularPrice.as
public class Price                                        public class RegularPrice extends Price
{                                                         {
  public class Price                                        ...
  {                                                         override public function get_charge (days_rented:int):Number
    public function get_price_code():int                    {
    {                                                         var result:Number=2;
      throw new Error("this method must be override:          if (days_rented > 2)
get_price_code()");                                           {
    }                                                           result+= days_rented - 2 * 1.5;
                                                              }
    public function get_charge (days_rented:int):Number       return result;
    {                                                       }
      throw new Error("this method must be override:        ...
days_rented()");                                          }
    }
  }                                                       // NewReleasePrice.as
}                                                         public class NewReleasePrice extends Price
                                                          {
                                                            ...
                                                            override public function get_charge (days_rented:int):Number
                                                            {
                                                              return days_rented * 3;
                                                            }
                                                            ...
                                                          }

                                                          // ChildrensPrice.as
                                                          public class ChildrensPrice extends Price
                                                          {
                                                            ...
                                                            override public function get_charge (days_rented:int):Number
                                                            {
                                                              var result:Number=1.5;
                                                              if (days_rented > 3)
                                                              {
                                                                result+= days_rented - 3 * 1.5;
                                                              }
                                                              return result;
                                                            }
                                                            ...
                                                          }
// Price.as                                               // RegularPrice.as
public class Price                                        public class RegularPrice extends Price
{                                                         {
  public class Price                                        ...
  {                                                         override public function get_charge (days_rented:int):Number
    public function get_price_code():int                    {
    {                                                         var result:Number=2;
      throw new Error("this method must be override:          if (days_rented > 2)
get_price_code()");                                           {
    }                                                           result+= days_rented - 2 * 1.5;
                                                              }
    public function get_charge (days_rented:int):Number       return result;
    {                                                       }
      throw new Error("this method must be override:        ...
days_rented()");                                          }
    }
  }                                                       // NewReleasePrice.as
}                                                         public class NewReleasePrice extends Price
                                                          {
                                                            ...
                                                            override public function get_charge (days_rented:int):Number
                                                            {
                                                              return days_rented * 3;
                                                            }
                                                            ...
                                                          }

                                                          // ChildrensPrice.as
                                                          public class ChildrensPrice extends Price
                                                          {
                                                            ...
                                                            override public function get_charge (days_rented:int):Number
                                                            {
                                                              var result:Number=1.5;
                                                              if (days_rented > 3)
                                                              {
                                                                result+= days_rented - 3 * 1.5;
                                                              }
                                                              return result;
                                                            }
                                                            ...
                                                          }
// Price.as                                               // RegularPrice.as
public class Price                                        public class RegularPrice extends Price
{                                                         {
  public class Price                                        ...
  {                                                         override public function get_charge (days_rented:int):Number
    public function get_price_code():int                    {
    {                                                         var result:Number=2;
      throw new Error("this method must be override:          if (days_rented > 2)
get_price_code()");                                           {
    }                                                           result+= days_rented - 2 * 1.5;
                                                              }
    public function get_charge (days_rented:int):Number       return result;
    {                                                       }
      throw new Error("this method must be override:        ...
days_rented()");                                          }
    }
  }                                                       // NewReleasePrice.as
}                                                         public class NewReleasePrice extends Price
                                                          {
                                                            ...
                                                            override public function get_charge (days_rented:int):Number
                                                            {
                                                              return days_rented * 3;
                                                            }
                                                            ...
                                                          }

                                                          // ChildrensPrice.as
                                                          public class ChildrensPrice extends Price
                                                          {
                                                            ...
                                                            override public function get_charge (days_rented:int):Number
                                                            {
                                                              var result:Number=1.5;
                                                              if (days_rented > 3)
                                                              {
                                                                result+= days_rented - 3 * 1.5;
                                                              }
                                                              return result;
                                                            }
                                                            ...
                                                          }
// Movie.as                                                        // Price.as
public class Movie                                                 public class Price
{                                                                  {
   ...                                                               ..
   public function get_bonus_points(days_rented:int):int             public function get_bonus_points(days_rented:int):int
   {                                                                 {
      //                  2     1                                       return 1;
      if (get_price_code() == Movie.NEW_RELEASE && days_rented >     }
1)                                                                   ..
      {                                                            }
         return 2;
      }                                                            // NewReleasePrice.as
      else                                                         public class NewReleasePrice
      {                                                            {
         return 1;                                                   ..
      }                                                              override public function get_bonus_points
   }                                                               (days_rented:int):int
   ..                                                                {
}                                                                       //                  2     1
                                                                        return (days_rented > 1) ? 2 : 1;
                                                                     }
                                                                     ..
                                                                   }
// Movie.as                                                        // Price.as
public class Movie                                                 public class Price
{                                                                  {
   ...                                                               ..
   public function get_bonus_points(days_rented:int):int             public function get_bonus_points(days_rented:int):int
   {                                                                 {
      //                  2     1                                       return 1;
      if (get_price_code() == Movie.NEW_RELEASE && days_rented >     }
1)                                                                   ..
      {                                                            }
         return 2;
      }                                                            // NewReleasePrice.as
      else                                                         public class NewReleasePrice
      {                                                            {
         return 1;                                                   ..
      }                                                              override public function get_bonus_points
   }                                                               (days_rented:int):int
   ..                                                                {
}                                                                       //                  2     1
                                                                        return (days_rented > 1) ? 2 : 1;
                                                                     }
                                                                     ..
                                                                   }
// Movie.as                                                        // Price.as
public class Movie                                                 public class Price
{                                                                  {
   ...                                                               ..
   public function get_bonus_points(days_rented:int):int             public function get_bonus_points(days_rented:int):int
   {                                                                 {
      //                  2     1                                       return 1;
      if (get_price_code() == Movie.NEW_RELEASE && days_rented >     }
1)                                                                   ..
      {                                                            }
         return 2;
      }                                                            // NewReleasePrice.as
      else                                                         public class NewReleasePrice
      {                                                            {
         return 1;                                                   ..
      }                                                              override public function get_bonus_points
   }                                                               (days_rented:int):int
   ..                                                                {
}                                                                       //                  2     1
                                                                        return (days_rented > 1) ? 2 : 1;
                                                                     }
                                                                     ..
                                                                   }
// Movie.as                                                        // Price.as
public class Movie                                                 public class Price
{                                                                  {
   ...                                                               ..
   public function get_bonus_points(days_rented:int):int             public function get_bonus_points(days_rented:int):int
   {                                                                 {
      //                  2     1                                       return 1;
      if (get_price_code() == Movie.NEW_RELEASE && days_rented >     }
1)                                                                   ..
      {                                                            }
         return 2;
      }                                                            // NewReleasePrice.as
      else                                                         public class NewReleasePrice
      {                                                            {
         return 1;                                                   ..
      }                                                              override public function get_bonus_points
   }                                                               (days_rented:int):int
   ..                                                                {
}                                                                       //                  2     1
                                                                        return (days_rented > 1) ? 2 : 1;
                                                                     }
                                                                     ..
                                                                   }
...
Refactoring in AS3
Refactoring in AS3
Thank You!
Ad

More Related Content

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
Lorin 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 2
Kevin Chun-Hsien Hsu
 
Mathcentre basic differentiation
Mathcentre basic differentiationMathcentre basic differentiation
Mathcentre basic differentiation
apwazap777
 
Advanced python
Advanced pythonAdvanced python
Advanced python
EU Edge
 
Mattbrenner
MattbrennerMattbrenner
Mattbrenner
Droidcon Berlin
 
The Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint LessonThe Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint Lesson
Paul Hawks
 
Design pattern - part 1
Design pattern - part 1Design pattern - part 1
Design pattern - part 1
Jieyi 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-dnn
Taiga Nomi
 
Dynamic programming burglar_problem
Dynamic programming burglar_problemDynamic programming burglar_problem
Dynamic programming burglar_problem
Russell Childs
 
Introduction à dart
Introduction à dartIntroduction à dart
Introduction à dart
yohanbeschi
 
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장 자동적으로 움직이는 게임 에이전트 생성법_2
suitzero
 
Class 21: Changing State
Class 21: Changing StateClass 21: Changing State
Class 21: Changing State
David 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 Personalization
Jacopo Mangiavacchi
 
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
Lorin 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 2
Kevin Chun-Hsien Hsu
 
Mathcentre basic differentiation
Mathcentre basic differentiationMathcentre basic differentiation
Mathcentre basic differentiation
apwazap777
 
Advanced python
Advanced pythonAdvanced python
Advanced python
EU Edge
 
The Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint LessonThe Chain Rule Powerpoint Lesson
The Chain Rule Powerpoint Lesson
Paul Hawks
 
Design pattern - part 1
Design pattern - part 1Design pattern - part 1
Design pattern - part 1
Jieyi 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-dnn
Taiga Nomi
 
Dynamic programming burglar_problem
Dynamic programming burglar_problemDynamic programming burglar_problem
Dynamic programming burglar_problem
Russell Childs
 
Introduction à dart
Introduction à dartIntroduction à dart
Introduction à dart
yohanbeschi
 
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장 자동적으로 움직이는 게임 에이전트 생성법_2
suitzero
 
Class 21: Changing State
Class 21: Changing StateClass 21: Changing State
Class 21: Changing State
David 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 Personalization
Jacopo Mangiavacchi
 

Similar to Refactoring in AS3 (20)

Refactoring Example
Refactoring ExampleRefactoring Example
Refactoring Example
liufabin 66688
 
Android Refactoring
Android RefactoringAndroid Refactoring
Android Refactoring
Godfrey Nolan
 
Refactoring Simple Example
Refactoring Simple ExampleRefactoring Simple Example
Refactoring Simple Example
liufabin 66688
 
SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper Talk
Nikolaos 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.docx
budabrooks46239
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - Strategy
Paul 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.pdf
4babies2010
 
J slider
J sliderJ slider
J slider
Sesum Dragomir
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
Chris Huang
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
chetan_p211
 
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
Brian 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 copy
Brian Aker
 
slides
slidesslides
slides
thamerr
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
Kaniska Mandal
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
Kris Wallsmith
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
Kaniska Mandal
 
Refactoring Simple Example
Refactoring Simple ExampleRefactoring Simple Example
Refactoring Simple Example
liufabin 66688
 
SANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper TalkSANER 2019 Most Influential Paper Talk
SANER 2019 Most Influential Paper Talk
Nikolaos 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.docx
budabrooks46239
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Java Patterns - Strategy
Java Patterns - StrategyJava Patterns - Strategy
Java Patterns - Strategy
Paul 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.pdf
4babies2010
 
重構—改善既有程式的設計(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 copy
Brian 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 copy
Brian Aker
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
Converting Db Schema Into Uml Classes
Converting Db Schema Into Uml ClassesConverting Db Schema Into Uml Classes
Converting Db Schema Into Uml Classes
Kaniska Mandal
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
Kris Wallsmith
 
Create a Customized GMF DnD Framework
Create a Customized GMF DnD FrameworkCreate a Customized GMF DnD Framework
Create a Customized GMF DnD Framework
Kaniska Mandal
 
Ad

More from Eddie Kao (20)

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

Recently uploaded (20)

Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
accessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electricaccessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electric
UXPA Boston
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptxUiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
anabulhac
 
Secondary Storage for a microcontroller system
Secondary Storage for a microcontroller systemSecondary Storage for a microcontroller system
Secondary Storage for a microcontroller system
fizarcse
 
Building a research repository that works by Clare Cady
Building a research repository that works by Clare CadyBuilding a research repository that works by Clare Cady
Building a research repository that works by Clare Cady
UXPA Boston
 
AI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological ImpactAI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological Impact
SaikatBasu37
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Understanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdfUnderstanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdf
Fulcrum Concepts, LLC
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More MachinesRefactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Refactoring meta-rauc-community: Cleaner Code, Better Maintenance, More Machines
Leon Anavi
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Right to liberty and security of a person.pdf
Right to liberty and security of a person.pdfRight to liberty and security of a person.pdf
Right to liberty and security of a person.pdf
danielbraico197
 
accessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electricaccessibility Considerations during Design by Rick Blair, Schneider Electric
accessibility Considerations during Design by Rick Blair, Schneider Electric
UXPA Boston
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptxUiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
UiPath AgentHack - Build the AI agents of tomorrow_Enablement 1.pptx
anabulhac
 
Secondary Storage for a microcontroller system
Secondary Storage for a microcontroller systemSecondary Storage for a microcontroller system
Secondary Storage for a microcontroller system
fizarcse
 
Building a research repository that works by Clare Cady
Building a research repository that works by Clare CadyBuilding a research repository that works by Clare Cady
Building a research repository that works by Clare Cady
UXPA Boston
 
AI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological ImpactAI and Gender: Decoding the Sociological Impact
AI and Gender: Decoding the Sociological Impact
SaikatBasu37
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Understanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdfUnderstanding SEO in the Age of AI.pdf
Understanding SEO in the Age of AI.pdf
Fulcrum Concepts, LLC
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 

Refactoring in AS3

  • 4. AS3 OOP Design Pattern
  • 5. ...
  • 7. B
  • 8. !?
  • 9. ?
  • 10. !=
  • 11. ?
  • 12. ?
  • 13. ?
  • 14. duplicated code, long method, large class, long parameter list...
  • 15. If it stinks, change it.
  • 16. Rule of Three Three strikes and you refactor
  • 17. ?
  • 18. ? ! ...
  • 19. ? ... !
  • 20. ? ... !
  • 21. Design Pattern (over-engineering)
  • 22. Design Pattern v.s. Refactoring
  • 24. !
  • 25. &
  • 26. !
  • 27. .. 1. 2. 3. 2 2 2 1.5 1.5 3 3 1.5 3 1 1 1
  • 29. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 30. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 31. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 32. // Customer.as // Customer.as public function checkout ():String public function checkout():String { { ... while(rentals.length > 0) while(rentals.length > 0) { { ... ... ... this_amount = amount_for(the_rental); ... switch(the_rental.get_movie().get_price_code()) } { .. case Movie.REGULAR: // } this_amount += 2; if (the_rental.get_days_rented() > 2) private function amount_for (the_rental:Rental):Number { { this_amount+=(the_rental.get_days_rented()-2)* 1.5; var result:int = 0; } switch (the_rental.get_movie().get_price_code()) break; { case Movie.REGULAR :// case Movie.NEW_RELEASE: // result += 2; this_amount += the_rental.get_days_rented() * 3; if (the_rental.get_days_rented() > 2) break; { result += (the_rental.get_days_rented() - 2) * 1.5; case Movie.CHILDRENS: // } this_amount += 1.5; break; if (the_rental.get_days_rented() > 3) { case Movie.NEW_RELEASE :// this_amount+=(the_rental.get_days_rented()-3)*1.5; result += the_rental.get_days_rented() * 3; } break; break; } case Movie.CHILDRENS :// ... result += 1.5; } if (the_rental.get_days_rented() > 3) { result += (the_rental.get_days_rented() - 3) * 1.5; } break; } return result; }
  • 34. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 35. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 36. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 37. // Customer.as // Customer.as public class Customer public class Customer { { .. private function amount_for (the_rental:Rental):Number private function amount_for (the_rental:Rental):Number { { return the_rental.get_charge(); var result:int = 0; } switch (the_rental.get_movie().get_price_code()) } { case Movie.REGULAR :// // Rental.as result += 2; public class Rental if (the_rental.get_days_rented() > 2) { { ... result += (the_rental.get_days_rented() - 2) * 1.5; public function get_charge():Number } { break; var result:int = 0; switch (get_movie().get_price_code()) case Movie.NEW_RELEASE :// { result += the_rental.get_days_rented() * 3; case Movie.REGULAR :// break; result += 2; if (get_days_rented() > 2) case Movie.CHILDRENS :// { result += 1.5; result += (get_days_rented() - 2) * 1.5; if (the_rental.get_days_rented() > 3) } { break; result += (the_rental.get_days_rented() - 3) * 1.5; } case Movie.NEW_RELEASE :// break; result += get_days_rented() * 3; } break; return result; case Movie.CHILDRENS :// } result += 1.5; .. if (get_days_rented() > 3) } { result += (get_days_rented() - 3) * 1.5; } break; } return result; } ... }
  • 38. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = the_rental.get_charge(); // // bonus_points += 1; bonus_points += 1; ... ... } } result += "n " + total_amount + "n"; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; result += " " + bonus_points + " "; return result; return result; } } .. .. } }
  • 39. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = the_rental.get_charge(); // // bonus_points += 1; bonus_points += 1; ... ... } } result += "n " + total_amount + "n"; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; result += " " + bonus_points + " "; return result; return result; } } .. .. } }
  • 40. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = the_rental.get_charge(); // // bonus_points += 1; bonus_points += 1; ... ... } } result += "n " + total_amount + "n"; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; result += " " + bonus_points + " "; return result; return result; } } .. .. } }
  • 41. Replace Temp with Query ...
  • 42. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // this_amount = amount_for(the_rental); bonus_points += 1; // // 2 1 bonus_points += 1; if ((the_rental.get_movie().get_price_code() == Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) // 2 1 { if ((the_rental.get_movie().get_price_code() == bonus_points += 1; Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) } { result += "-" + the_rental.get_movie().get_title() + " " + bonus_points += 1; the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); result += "-" + the_rental.get_movie().get_title() + " " + } this_amount +" n"; total_amount += this_amount; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; result += "n " + total_amount + "n"; return result; result += " " + bonus_points + " "; } return result; }
  • 43. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // this_amount = amount_for(the_rental); bonus_points += 1; // // 2 1 bonus_points += 1; if ((the_rental.get_movie().get_price_code() == Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) // 2 1 { if ((the_rental.get_movie().get_price_code() == bonus_points += 1; Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) } { result += "-" + the_rental.get_movie().get_title() + " " + bonus_points += 1; the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); result += "-" + the_rental.get_movie().get_title() + " " + } this_amount +" n"; total_amount += this_amount; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; result += "n " + total_amount + "n"; return result; result += " " + bonus_points + " "; } return result; }
  • 44. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals; var rentals:Array = _rentals; var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // this_amount = amount_for(the_rental); bonus_points += 1; // // 2 1 bonus_points += 1; if ((the_rental.get_movie().get_price_code() == Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) // 2 1 { if ((the_rental.get_movie().get_price_code() == bonus_points += 1; Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) } { result += "-" + the_rental.get_movie().get_title() + " " + bonus_points += 1; the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); result += "-" + the_rental.get_movie().get_title() + " " + } this_amount +" n"; total_amount += this_amount; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; result += "n " + total_amount + "n"; return result; result += " " + bonus_points + " "; } return result; }
  • 46. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 47. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 48. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 49. // Customer.as // Customer.as public function checkout ():String public function checkout ():String { { ... while (rentals.length > 0) ... { while (rentals.length > 0) var this_amount:Number = 0; { var the_rental:Rental = rentals.shift() as Rental; var this_amount:Number = 0; var the_rental:Rental = rentals.shift() as Rental; this_amount = amount_for(the_rental); this_amount = amount_for(the_rental); // bonus_points += 1; // bonus_points += the_rental.get_bonus_points(); // 2 1 if ((the_rental.get_movie().get_price_code() == result += "-" + the_rental.get_movie().get_title() + " " + Movie.NEW_RELEASE) && (the_rental.get_days_rented() > 1)) this_amount +" n"; { total_amount += this_amount; bonus_points += 1; } } ... } result += "-" + the_rental.get_movie().get_title() + " " + this_amount +" n"; // Rental.as total_amount += this_amount; public class Rental } { ... .. } public function get_bonus_points():int { // 2 1 if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && (get_days_rented() > 1)) { return 2; } else { return 1; } } .. }
  • 50. Replace Temp with Query ...
  • 51. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 52. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 53. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 54. // Customer.as // Customer.as public class Customer public class Customer { { ... public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // // bonus_points += the_rental.get_bonus_points(); bonus_points += the_rental.get_bonus_points(); result += "-" + the_rental.get_movie().get_title() + " " result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; + the_rental.get_charge() +" n"; } total_amount += the_rental.get_charge(); } result += "n " + get_total_charge() + "n"; result += " " + bonus_points + " "; result += "n " + total_amount + "n"; result += " " + bonus_points + " "; return result; } return result; } private function get_total_charge():Number ... { } var rentals:Array = _rentals.concat(); var result:Number = 0; while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_charge(); } return result; } }
  • 55. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 56. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 57. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 58. // Customer.as // Customer.as public class Customer public class Customer { { .. .. public function checkout ():String public function checkout ():String { { var total_amount:Number = 0;// var total_amount:Number = 0;// var bonus_points:int = 0;// var bonus_points:int = 0;// var rentals:Array = _rentals.concat(); var rentals:Array = _rentals.concat(); var result:String = get_name() +" n"; var result:String = get_name() +" n"; while (rentals.length > 0) while (rentals.length > 0) { { var the_rental:Rental = rentals.shift() as Rental; var the_rental:Rental = rentals.shift() as Rental; // result += "-" + the_rental.get_movie().get_title() + " " bonus_points += the_rental.get_bonus_points(); + the_rental.get_charge() +" n"; } result += "-" + the_rental.get_movie().get_title() + " " + the_rental.get_charge() +" n"; result += "n " + get_total_charge() + "n"; total_amount += the_rental.get_charge(); result += " " + get_total_bonus_points() + " "; } return result; result += "n " + total_amount + "n"; } result += " " + bonus_points + " "; private function get_total_bonus_points():int return result; { } var rentals:Array = _rentals.concat(); .. var result:int = 0; } while (rentals.length > 0) { var the_rental:Rental = rentals.shift() as Rental; result += the_rental.get_bonus_points(); } return result; } .. }
  • 59. Move Method ...
  • 60. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 61. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 62. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 63. // Rental.as // Rental.as public class Rental public class Rental { { ... public function get_charge():Number public function get_charge():Number { { return _movie.get_charge(_days_rented); var result:int = 0; } switch (get_movie().get_price_code()) } { case Movie.REGULAR :// // Movie.as result += 2; public class Movie if (get_days_rented() > 2) { { public function get_charge(days_rented:int):Number result += (get_days_rented() - 2) * 1.5; { } var result:int = 0; break; switch (get_price_code()) { case Movie.NEW_RELEASE :// case Movie.REGULAR :// result += get_days_rented() * 3; result += 2; break; if (days_rented > 2) { case Movie.CHILDRENS :// result += (days_rented - 2) * 1.5; result += 1.5; } if (get_days_rented() > 3) break; { result += (get_days_rented() - 3) * 1.5; case Movie.NEW_RELEASE :// } result += days_rented * 3; break; break; } case Movie.CHILDRENS :// return result; result += 1.5; } if (days_rented > 3) .. { } result += (days_rented - 3) * 1.5; } break; } return result; } }
  • 64. // Rental.as // Rental.as public class Rental public class Rental { { ... .. public function get_bonus_points():int public function get_charge():Number { { // 2 1 return _movie.get_bonus_points(_days_rented); if ((get_movie().get_price_code() == Movie.NEW_RELEASE) && } (get_days_rented() > 1)) .. { } return 2; } // Movie.as else public class Movie { { return 1; .. } public function get_bonus_points(days_rented:int):int } { .. // 2 1 } if ((get_price_code() == Movie.NEW_RELEASE) && (days_rented > 1)) { return 2; } else { return 1; } } .. }
  • 65. // 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; } } .. }
  • 66. // 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; } } .. }
  • 67. // 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; } } .. }
  • 69. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String;// private var _title:String;// private var _price_code:int;// private var _price_code:int;// public function Movie (title:String,price_code:int):void public function Movie (title:String,price_code:int):void { { _title = title; _title = title; _price_code = price_code; set_price_code(price_code); } } ... ... } }
  • 70. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String;// private var _title:String;// private var _price_code:int;// private var _price_code:int;// public function Movie (title:String,price_code:int):void public function Movie (title:String,price_code:int):void { { _title = title; _title = title; _price_code = price_code; set_price_code(price_code); } } ... ... } }
  • 71. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String;// private var _title:String;// private var _price_code:int;// private var _price_code:int;// public function Movie (title:String,price_code:int):void public function Movie (title:String,price_code:int):void { { _title = title; _title = title; _price_code = price_code; set_price_code(price_code); } } ... ... } }
  • 73. // Price.as // RegularPrice.as public class Price public class RegularPrice extends Price { { public function get_price_code():int override public function get_price_code():int { { throw new Error("method must be overrided: return Movie.REGULAR; get_price_code"); } } } } // NewReleasePrice.as public class NewReleasePrice extends Price { override public function get_price_code():int { return Movie.NEW_RELEASE; } } // ChildrensPrice.as public class ChildrensPrice extends Price { override public function get_price_code():int { return Movie.CHILDRENS; } }
  • 74. // Price.as // RegularPrice.as public class Price public class RegularPrice extends Price { { public function get_price_code():int override public function get_price_code():int { { throw new Error("method must be overrided: return Movie.REGULAR; get_price_code"); } } } } // NewReleasePrice.as public class NewReleasePrice extends Price { override public function get_price_code():int { return Movie.NEW_RELEASE; } } // ChildrensPrice.as public class ChildrensPrice extends Price { override public function get_price_code():int { return Movie.CHILDRENS; } }
  • 75. // Price.as // RegularPrice.as public class Price public class RegularPrice extends Price { { public function get_price_code():int override public function get_price_code():int { { throw new Error("method must be overrided: return Movie.REGULAR; get_price_code"); } } } } // NewReleasePrice.as public class NewReleasePrice extends Price { override public function get_price_code():int { return Movie.NEW_RELEASE; } } // ChildrensPrice.as public class ChildrensPrice extends Price { override public function get_price_code():int { return Movie.CHILDRENS; } }
  • 76. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 77. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 78. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 79. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 80. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 81. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 82. // Movie.as // Movie.as public class Movie public class Movie { { ... ... private var _title:String; // private var _title:String; // private var _price_code:int; // private var _price:Price; // public function get_price_code ():int public function get_price_code ():int { { return _price_code; return _price.get_price_code(); } } public function set_price_code (arg:int):void public function set_price_code (arg:int):void { { _price_code = arg; switch(arg) } { .. case REGULAR: } _price = new RegularPrice(); break; case NEW_RELEASE: _price = new NewReleasePrice(); break; case CHILDRENS: _price = new ChildrensPrice(); break; default: throw new Error("wrong price code"); } } .. }
  • 83. Move Method ...
  • 84. // Movie.as // Movie.as public class Movie public class Movie { { ... public function get_charge (days_rented:int):Number public function get_charge (days_rented:int):Number { { return _price.get_charge(days_rented); var result:int=0; } switch (get_price_code()) } { case Movie.REGULAR :// // Price.as result+= 2; public class Price if (days_rented > 2) { { .. result+= days_rented - 2 * 1.5; public function get_charge (days_rented:int):Number } { break; var result:int=0; switch (get_price_code()) case Movie.NEW_RELEASE :// { result+= days_rented * 3; case Movie.REGULAR :// break; result+= 2; if (days_rented > 2) case Movie.CHILDRENS :// { result+= 1.5; result+= days_rented - 2 * 1.5; if (days_rented > 3) } { break; result+= days_rented - 3 * 1.5; } case Movie.NEW_RELEASE :// break; result+= days_rented * 3; } break; return result; } case Movie.CHILDRENS :// .. result+= 1.5; } if (days_rented > 3) { result+= days_rented - 3 * 1.5; } break; } return result; } .. }
  • 85. // Movie.as // Movie.as public class Movie public class Movie { { ... public function get_charge (days_rented:int):Number public function get_charge (days_rented:int):Number { { return _price.get_charge(days_rented); var result:int=0; } switch (get_price_code()) } { case Movie.REGULAR :// // Price.as result+= 2; public class Price if (days_rented > 2) { { .. result+= days_rented - 2 * 1.5; public function get_charge (days_rented:int):Number } { break; var result:int=0; switch (get_price_code()) case Movie.NEW_RELEASE :// { result+= days_rented * 3; case Movie.REGULAR :// break; result+= 2; if (days_rented > 2) case Movie.CHILDRENS :// { result+= 1.5; result+= days_rented - 2 * 1.5; if (days_rented > 3) } { break; result+= days_rented - 3 * 1.5; } case Movie.NEW_RELEASE :// break; result+= days_rented * 3; } break; return result; } case Movie.CHILDRENS :// .. result+= 1.5; } if (days_rented > 3) { result+= days_rented - 3 * 1.5; } break; } return result; } .. }
  • 86. // Movie.as // Movie.as public class Movie public class Movie { { ... public function get_charge (days_rented:int):Number public function get_charge (days_rented:int):Number { { return _price.get_charge(days_rented); var result:int=0; } switch (get_price_code()) } { case Movie.REGULAR :// // Price.as result+= 2; public class Price if (days_rented > 2) { { .. result+= days_rented - 2 * 1.5; public function get_charge (days_rented:int):Number } { break; var result:int=0; switch (get_price_code()) case Movie.NEW_RELEASE :// { result+= days_rented * 3; case Movie.REGULAR :// break; result+= 2; if (days_rented > 2) case Movie.CHILDRENS :// { result+= 1.5; result+= days_rented - 2 * 1.5; if (days_rented > 3) } { break; result+= days_rented - 3 * 1.5; } case Movie.NEW_RELEASE :// break; result+= days_rented * 3; } break; return result; } case Movie.CHILDRENS :// .. result+= 1.5; } if (days_rented > 3) { result+= days_rented - 3 * 1.5; } break; } return result; } .. }
  • 87. // Movie.as // Movie.as public class Movie public class Movie { { ... public function get_charge (days_rented:int):Number public function get_charge (days_rented:int):Number { { return _price.get_charge(days_rented); var result:int=0; } switch (get_price_code()) } { case Movie.REGULAR :// // Price.as result+= 2; public class Price if (days_rented > 2) { { .. result+= days_rented - 2 * 1.5; public function get_charge (days_rented:int):Number } { break; var result:int=0; switch (get_price_code()) case Movie.NEW_RELEASE :// { result+= days_rented * 3; case Movie.REGULAR :// break; result+= 2; if (days_rented > 2) case Movie.CHILDRENS :// { result+= 1.5; result+= days_rented - 2 * 1.5; if (days_rented > 3) } { break; result+= days_rented - 3 * 1.5; } case Movie.NEW_RELEASE :// break; result+= days_rented * 3; } break; return result; } case Movie.CHILDRENS :// .. result+= 1.5; } if (days_rented > 3) { result+= days_rented - 3 * 1.5; } break; } return result; } .. }
  • 88. Replace Conditional with Polymorphism
  • 89. // Price.as // RegularPrice.as public class Price public class RegularPrice extends Price { { public class Price ... { override public function get_charge (days_rented:int):Number public function get_price_code():int { { var result:Number=2; throw new Error("this method must be override: if (days_rented > 2) get_price_code()"); { } result+= days_rented - 2 * 1.5; } public function get_charge (days_rented:int):Number return result; { } throw new Error("this method must be override: ... days_rented()"); } } } // NewReleasePrice.as } public class NewReleasePrice extends Price { ... override public function get_charge (days_rented:int):Number { return days_rented * 3; } ... } // ChildrensPrice.as public class ChildrensPrice extends Price { ... override public function get_charge (days_rented:int):Number { var result:Number=1.5; if (days_rented > 3) { result+= days_rented - 3 * 1.5; } return result; } ... }
  • 90. // Price.as // RegularPrice.as public class Price public class RegularPrice extends Price { { public class Price ... { override public function get_charge (days_rented:int):Number public function get_price_code():int { { var result:Number=2; throw new Error("this method must be override: if (days_rented > 2) get_price_code()"); { } result+= days_rented - 2 * 1.5; } public function get_charge (days_rented:int):Number return result; { } throw new Error("this method must be override: ... days_rented()"); } } } // NewReleasePrice.as } public class NewReleasePrice extends Price { ... override public function get_charge (days_rented:int):Number { return days_rented * 3; } ... } // ChildrensPrice.as public class ChildrensPrice extends Price { ... override public function get_charge (days_rented:int):Number { var result:Number=1.5; if (days_rented > 3) { result+= days_rented - 3 * 1.5; } return result; } ... }
  • 91. // Price.as // RegularPrice.as public class Price public class RegularPrice extends Price { { public class Price ... { override public function get_charge (days_rented:int):Number public function get_price_code():int { { var result:Number=2; throw new Error("this method must be override: if (days_rented > 2) get_price_code()"); { } result+= days_rented - 2 * 1.5; } public function get_charge (days_rented:int):Number return result; { } throw new Error("this method must be override: ... days_rented()"); } } } // NewReleasePrice.as } public class NewReleasePrice extends Price { ... override public function get_charge (days_rented:int):Number { return days_rented * 3; } ... } // ChildrensPrice.as public class ChildrensPrice extends Price { ... override public function get_charge (days_rented:int):Number { var result:Number=1.5; if (days_rented > 3) { result+= days_rented - 3 * 1.5; } return result; } ... }
  • 92. // Movie.as // Price.as public class Movie public class Price { { ... .. public function get_bonus_points(days_rented:int):int public function get_bonus_points(days_rented:int):int { { // 2 1 return 1; if (get_price_code() == Movie.NEW_RELEASE && days_rented > } 1) .. { } return 2; } // NewReleasePrice.as else public class NewReleasePrice { { return 1; .. } override public function get_bonus_points } (days_rented:int):int .. { } // 2 1 return (days_rented > 1) ? 2 : 1; } .. }
  • 93. // Movie.as // Price.as public class Movie public class Price { { ... .. public function get_bonus_points(days_rented:int):int public function get_bonus_points(days_rented:int):int { { // 2 1 return 1; if (get_price_code() == Movie.NEW_RELEASE && days_rented > } 1) .. { } return 2; } // NewReleasePrice.as else public class NewReleasePrice { { return 1; .. } override public function get_bonus_points } (days_rented:int):int .. { } // 2 1 return (days_rented > 1) ? 2 : 1; } .. }
  • 94. // Movie.as // Price.as public class Movie public class Price { { ... .. public function get_bonus_points(days_rented:int):int public function get_bonus_points(days_rented:int):int { { // 2 1 return 1; if (get_price_code() == Movie.NEW_RELEASE && days_rented > } 1) .. { } return 2; } // NewReleasePrice.as else public class NewReleasePrice { { return 1; .. } override public function get_bonus_points } (days_rented:int):int .. { } // 2 1 return (days_rented > 1) ? 2 : 1; } .. }
  • 95. // Movie.as // Price.as public class Movie public class Price { { ... .. public function get_bonus_points(days_rented:int):int public function get_bonus_points(days_rented:int):int { { // 2 1 return 1; if (get_price_code() == Movie.NEW_RELEASE && days_rented > } 1) .. { } return 2; } // NewReleasePrice.as else public class NewReleasePrice { { return 1; .. } override public function get_bonus_points } (days_rented:int):int .. { } // 2 1 return (days_rented > 1) ? 2 : 1; } .. }
  • 96. ...