Chapter 5 Flashcards
Duck Types
Duck types are public interfaces that are not tied to any specific class. These across-class interfaces add enormous flexibility to your application by replacing costly dependencies on class with more forgiving dependencies on messages.
Polymorphism
The state of having many forms.
Polymorphism in OOP refers to the ability of many different objects to respond to the same message. Senders of the message need not care about the class of the receiver ; receivers supply their own specific version of the behavior.
There are a number of ways to achieve polymorphism; duck typing, as you have surely guessed, is one. Inheritance and behavior sharing (via Ruby modules) are others.
Polymorphism
The state of having many forms.
Polymorphism in OOP refers to the ability of many different objects to respond to the same message. Senders of the message need not care about the class of the receiver ; receivers supply their own specific version of the behavior.
There are a number of ways to achieve polymorphism; duck typing, as you have surely guessed, is one. Inheritance and behavior sharing (via Ruby modules) are others.
Statically or dynamically typed languages.
Programming languages are either statically or dynamically typed. Most (though not all) statically typed languages require that you explicitly declare the type of each variable and every method parameter.
Dynamically typed languages omit this requirement; they allow you to put any value in any variable and pass any argument to any method, without further declaration. Ruby, obviously, is dynamically typed.
Statically or dynamically typed languages.
Programming languages are either statically or dynamically typed. Most (though not all) statically typed languages require that you explicitly declare the type of each variable and every method parameter.
Dynamically typed languages omit this requirement; they allow you to put any value in any variable and pass any argument to any method, without further declaration. Ruby, obviously, is dynamically typed.
Metaprogramming
??
writing code that writes code
Chap 5 Summary
Messages are at the center of object-oriented applications and they pass among objects along public interfaces. Duck typing detaches these public interfaces from specific classes, creating virtual types that are defined by what they do instead of by who they are.
Duck typing reveals underlying abstractions that might otherwise be invisible. Depending on these abstractions reduces risk and increases flexibility, making your application cheaper to maintain and easier to change.