Page 245 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 245

Unit 12: Refactoring



            12.1.1 Refactoring Basic Examples                                                     Notes
            The sample program is very easy. It is a program to computer and print a statement of a
            customer’s charges at a video store. The program is told which movies a customer rented and
            for how long. It then calculates the charges, which depend on how long the movie is rented,
            and identifies the type movie. There are three kinds of movies: regular, children’s, and new
            releases. In addition to calculating charges, the statement also computes frequent renter points,
            which vary depending on whether the film is a new release. Several classes represent various
            video elements. Here is a class diagram to show them Figure 12.1.

                           Figure 12.1: Class Diagram (Movie+Rental+Customer)











            The code for each of these classes in turn is shown Movie
            Movie is just a simple data class.
                     public class Movie (
                     public static final in CHILDRENS = 2;
                     public static final nit REGULAR = 0;
                     public static final int NEW RELEASE = I;
                     private String _title
                     private int _priceCode;
                     public Movie(String title, int priceCode)
                     {__price Code = priecCode;
                     public int getPriceCode() { return _priceCode;
                     public void setPriceCode(intarg)
                     { _priecCode = arg: title = title;
                     public String get Title return _title:
            Rental
            The rental class represents a customer renting a movie:
                     class Rental
                      private Movie _movie;
                      private int claysRented;
                     public Rental(Movie movie, int daysRented)
                     { movie = movie;
                     clavsRented = daysRented;
                      public int getDaysRentedu {
                      return _davsRented,
                     public Movie getMovieu()
                     { return _movie,
                     } };


                                             LOVELY PROFESSIONAL UNIVERSITY                                   239
   240   241   242   243   244   245   246   247   248   249   250