Chapter 12 - OO Concepts Flashcards Preview

Advanced Topics in Programming Languages > Chapter 12 - OO Concepts > Flashcards

Flashcards in Chapter 12 - OO Concepts Deck (39):

which PL serves as the originator of OO programming



3 benefits of inheritance

-a new ADT can "inherit" some or all of its data and behavior from an existing type and modify that type without affecting it

-allows for code reuse without harming original

-is hierarchical in nature and well suited to modeling descendant relationships


what is a derived class?

the class defined using inheritance (subclass is not entirely accurate)


what is a parent class?

the class being inherited from (superclass isn't entirely accurate)


what is a message protocol or message interface

the entire collection of methods of an object


message passing vs subroutine call

message passing implies a request to an object to execute one of its methods that partially entails operating on the object itself

subroutines typically process data sent by the caller


class variables/methods vs instance variables/methods

class variables/methods only have one copy per class and are shared by all instance of the class

instance variables/methods have one copy for each instance of the class and are only used by the instance to which they belong


1 disadvantage of inheritance

creates interdependencies among classes that complicate maintenance


what is dynamic dispatch?

the dynamic binding of messages to method definitions. AKA the messages are statically coded but the receiving object is determined at runtime.

This creates polymorphism of sorts


What is the way in which dynamic dispatch is most often implemented?

through abstract methods (pure virtual methods in C++)


8 design issues for OO PLs

-the exclusivity of objects

-are subclasses subtypes

-type checking and polymorphism

-single or multiple inheritance allowed

-allocation and deallocation of objects

-dynamic and static binding

-nested classes

-object initialization


What does "exclusivity of objects" mean

it refers to how objects are used in the PL and what kinds of data are represented by objects


3 approaches to the exclusivity of objects

-everything is an object (Ruby)

-add objects to a complete typing system (C++)

-include an imperative-style typing system for primitives but make everything else objects (Java)


1 advantage and 1 disadvantage to everything as an object exclusivity approach

Adv: elegance and purity

dis: slow operations on simple objects


1 advantage and 1 disadvantage of adding objects to complete typing system exclusivity approach

adv: fast operations on simple objects

dis: results in a confusing type system


1 advantage and 1 disadvantage of an imperative style system for primitives and objects for everything else exclusivity approach

adv: fast operations on simple objects and relatively small typing system

dis: still some confusion because of two type systems


4 things that must hold for a derived class to be a subtype

-the "is-a" relationship holds between the base class object and an object of the derived class

-if the derived class is also a parent class, then objects of the derived class must expose all of the members that are exposed by objects of the parent class

-at a minimum, an "is-a" relationship should guarantee that in a client a variable of the derived class type could appear anywhere a variable of the parent class type was legal (syntactically equivalent)

-the derived class objects should be behaviorally equivalent to the parent class objects when used as a parent class object (Liskov substitution principle - aka semantically equivalent)


What must be done to allow overridden method to be type checked statically

must have the same parameter types and return type


2 design issues with multiple inheritance

-complexity = two base classes could name the same variable or have a common ancestor

-efficiency = more of a perceived issue than a real issue


2 advantages of allocating objects on the heap?

-creates a uniform method of creation and access through pointer or reference variables

-simplifies assignment and implicit dereferencing


What is object slicing?

some information is lost about an object that is allocated on the stack

this occurs when an object on the stack adds a data field and then a child class is assigned as a reference to its base and that data is no longer reachable


What is the purpose of a nested class

allows information to be hidden in one class and be visible to another (nested) class

-kind of equivalent to friends in C++


2 design issues of nested classes

-what bits of the nesting class should be visible in the nested class

-should any of the nested class be visible in the nesting class


3 design issues with object initialization

-should an object be initialized manually (aka by the constructor only)?

-should objects be implicitly initialized

-when creating a derived class object, should the base be initialized implicitly or should the programmer explicitly manage that


4 general characteristics of C++ in regard to OO concepts

-mixed typing system (primitive types and objects)

-constructors and destructors

-elaborate access controls to class entities

-allows nested classes


3 inheritance characteristics of C++

-a class need not be subclasses of any type

-has private, protected, public access controls for inherited members

-supports multiple inheritance


C++ private vs public inheritance

private - in derived class any public or protected members from parent class are now private
(these now private members and methods need to be accessed by scope resolution operator ::)

public - in derived class any protected or public members from parent class are public or protected respectively


what is boxing?

the coercing of primitive types to their corresponding wrapper class types. Most notably in Java


5 characteristics of Java interfaces in their interaction with classes

-can only contain constants and method declarations

-a class can implement any number of interfaces

-interfaces can be used to simulate multiple inheritance

-no code reuse

-two interfaces with methods of the same name cannot be implemented in the same class


What is the Ada equivalent of a class? what are 3 properties?

-tagged types (tagged referring to a construct that expresses the type of the entity at the system level)

-can be records or private types

-no implicit constructor calls

-defined in packages and can thus be separately compiled


2 characteristics of inheritance in Ada

-only tagged types can be inherited from

-no private/protected inheritance, the derived class gets everything


4 OO characteristics in Eiffel PL

-has primitive types and objects

-all objects get three operations: copy, clone, and equal

-object creation is done with '!!' operator

constructors are defined in a creation clause and are explicitly called


what are methods called in Eiffel



what are instance variables called in Eiffel



What are "features" in Eiffel

the routines and attributes of a class together


7 inheritance characteristics of Eiffel

-supports multiple inheritance

-parent of a class is specified with the "inherit" clause

-with no access modifier, entities are essentially public

-using the name of the class as an access modifier = protected

-the "none" access modifier = private

-the "undefine" clause can be used to hide features from subclasses

-abstract classes can be created by using the "deferred" modifier on the class definition


what is the "redefine" clause in Eiffel

defines an overridden feature


what is the "rename" clause in Eiffel

same as :: scope modifier for accessing the parent version of an overridden feature


what is "design by contract" in Eiffel

formal properties of a class that are enforced by assertions expressed as:

-routine pre-conditions
-routine post-conditions
-class invariants