The Object Model Flashcards
What is encapsulation in Object Oriented Programming?
Encapsulation is hiding pieces of functionality and making it unavailable to the rest of the code base. It is a form of data protection, so that data cannot be manipulated or changed without obvious intention.
What is polymorphism in Object Oriented Programming?
Polymorphism is the ability for data to be represented as many different types.
What is inheritance?
The concept of inheritance is used in Ruby where a class inherits the behaviors of another class, referred to as the superclass. This gives Ruby programmers the power to define basic classes with large reusability and smaller subclasses for more fine-grained, detailed behaviors.
Besides inheritance, what is another way to utilize polymorphism in Ruby?
Using modules. Modules are similar to classes in that they contain shared behavior. However, you cannot create an object with a module. A module must be mixed in with a class using the reserved word ‘include’. This is called a mixin. After mixing in a module, the behaviors declared in that module are available to the class and its objects.
How does Ruby define the attributes and behaviors of it’s objects?
Ruby defines the attributes and behaviors of its objects in classes. You can think of classes as basic outlines of what an object should be made of and what it should be able to do.
What is instantiation?
This entire workflow of creating a new object or instance from a class is called instantiation.
Example:
class GoodDog
end
sparky = GoodDog.new
In the above example we can say that we’ve instantiated an object called sparky from the class GoodDog.
How can you see the lookup chain for a method?
With the ‘ancestors’ method.