Chapter 6 Flashcards

1
Q

Single inheritance.

A

whereby a subclass is allowed only one parent superclass. Ruby does this; it has single inheritance. A superclass may have many subclasses, but each subclass is permitted only one superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Single inheritance.

A

whereby a subclass is allowed only one parent superclass. Ruby does this; it has single inheritance. A superclass may have many subclasses, but each subclass is permitted only one superclass.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Template method pattern

A

This technique of defining a basic structure in the superclass and sending messages to acquire subclass-specific contributions is known as the template method pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Raise

A
class Bicycle 
      #... 
      def default_tire_size
          raise NotImplementedError,
              "This #{ self.class} cannot       respond to:"
       end 
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Chapter 6 Summary

A

Inheritance solves the problem of related types that share a great deal of common behavior but differ across some dimension. It allows you to isolate shared code and implement common algorithms in an abstract class, while also providing a structure that permits subclasses to contribute specializations.

The best way to create an abstract superclass is by pushing code up from concrete subclasses. Identifying the correct abstraction is easiest if you have access to at least three existing concrete classes. This chapter’s simple example relied on just two but in the real world you are often better served to wait for the additional information that three cases supply.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Chapter 6 Summary

A

Inheritance solves the problem of related types that share a great deal of common behavior but differ across some dimension. It allows you to isolate shared code and implement common algorithms in an abstract class, while also providing a structure that permits subclasses to contribute specializations.

The best way to create an abstract superclass is by pushing code up from concrete subclasses. Identifying the correct abstraction is easiest if you have access to at least three existing concrete classes. This chapter’s simple example relied on just two but in the real world you are often better served to wait for the additional information that three cases supply.

Abstract superclasses use the template method pattern to invite inheritors to supply specializations, and use hook methods to allow these inheritors to contribute these specializations without being forced to send super. Hook methods allow subclasses to contribute specializations without knowing the abstract algorithm. They remove the need for subclasses to send super and therefore reduce the coupling between layers of the hierarchy and increase its tolerance for change.

Well-designed inheritance hierarchies are easy to extend with new subclasses, even for programmers who know very little about the application. This ease of extension is inheritance’s greatest strength. When your problem is one of needing numerous specializations of a stable, common abstraction, inheritance can be an extremely low-cost solution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly