Team LiB
Previous Section Next Section

Exercises

  1. Given the following pairs of classes, what associations might exist between them from the perspective of the CRRS case study described in Appendix B?

    • EmployeeConferenceRoom

    • EmployeeMeeting

  2. Go back to your solution for exercise No. 3 at the end of Chapter 2. For all of the classes you suggested, list the pairwise associations that you might envision occurring between them.

  3. If the class FeatureFilm were defined to have the following methods:

                public void Update(Actor a, string title);
                public void Update(Actor a, Actor b, string title);
                public void Update(string topic, string title);
    

    which of the following additional headers would be allowed by the compiler?

                public bool Update(string category, string theater);
                public bool Update(string title, Actor a);
                public void Update(Actor b, Actor a, string title);
                public void Update(Actor a, Actor b);
    
  4. Given the following simplistic code, which illustrates overloading, overriding, and straight inheritance of methods:

              class Vehicle
              {
                string name;
    
                public virtual void Fuel(string fuelType) {
                  // details omitted ...
                }
    
                public virtual bool Fuel(string fuelType, int amount) {
                  // details omitted ...
                }
              }
    
              class Automobile : Vehicle
              {
                public virtual void Fuel(string fuelType, string timeFueled) {
                  // details omitted ...
                }
    
                public override bool Fuel(string fuelType, int amount) {
                  // ...
                }
              }
              class Truck : Vehicle
              {
                public override void Fuel(string fuelType) {
                  // ...
                }
              }
    
              class SportsCar : Automobile
              {
                public override void Fuel(string fuelType) {
                  // ...
                }
    
                public override void Fuel(string fuelType, string timeFueled) {
                  // ...
                }
              }
    
              // Client code:
    
              Truck t = new Truck();
              SportsCar sc = new SportsCar();
    

    how many different Fuel method signatures would each of the four classes recognize?

  5. Given the following simplistic classes:

          class FarmAnimal
          {
            string name;
    
            public virtual string Name {
              get {
                return name;
              }
              set {
                name = value;
              }
            }
    
            public virtual void MakeSound() {
              Console.WriteLine(Name + " makes a sound ...");
            }
          }
          class Cow : FarmAnimal
          {
            public override void MakeSound() {
              Console.WriteLine(Name + " goes Moooooo ...");
            }
          }
    
          class Horse : FarmAnimal
          {
            public override string Name {
              set {
                base.Name = value + " [a Horse]";
              }
            }
          }
    

    what would be printed by the following client code?

          Cow c = new Cow();
          Horse h = new Horse();
          c.Name = "Elsie";
          h.Name = "Mr. Ed";
          c.MakeSound();
          h.MakeSound();
    

Team LiB
Previous Section Next Section