Chapter 12 - OO Concepts Flashcards

1
Q

which PL serves as the originator of OO programming

A

SIMULA 67

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

3 benefits of inheritance

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a derived class?

A

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

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

what is a parent class?

A

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

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

what is a message protocol or message interface

A

the entire collection of methods of an object

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

message passing vs subroutine call

A

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

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

class variables/methods vs instance variables/methods

A

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

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

1 disadvantage of inheritance

A

creates interdependencies among classes that complicate maintenance

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

what is dynamic dispatch?

A

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

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

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

A

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

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

8 design issues for OO PLs

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does “exclusivity of objects” mean

A

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

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

3 approaches to the exclusivity of objects

A
  • 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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

Adv: elegance and purity

dis: slow operations on simple objects

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

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

A

adv: fast operations on simple objects
dis: results in a confusing type system

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

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

A

adv: fast operations on simple objects and relatively small typing system
dis: still some confusion because of two type systems

17
Q

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

A
  • 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)
18
Q

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

A

must have the same parameter types and return type

19
Q

2 design issues with multiple inheritance

A
  • complexity = two base classes could name the same variable or have a common ancestor
  • efficiency = more of a perceived issue than a real issue
20
Q

2 advantages of allocating objects on the heap?

A
  • creates a uniform method of creation and access through pointer or reference variables
  • simplifies assignment and implicit dereferencing
21
Q

What is object slicing?

A

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

22
Q

What is the purpose of a nested class

A

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

-kind of equivalent to friends in C++

23
Q

2 design issues of nested classes

A
  • 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
24
Q

3 design issues with object initialization

A
  • 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
25
Q

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

A
  • mixed typing system (primitive types and objects)
  • constructors and destructors
  • elaborate access controls to class entities
  • allows nested classes
26
Q

3 inheritance characteristics of C++

A
  • a class need not be subclasses of any type
  • has private, protected, public access controls for inherited members
  • supports multiple inheritance
27
Q

C++ private vs public inheritance

A
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

28
Q

what is boxing?

A

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

29
Q

5 characteristics of Java interfaces in their interaction with classes

A
  • 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
30
Q

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

A
  • 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
31
Q

2 characteristics of inheritance in Ada

A
  • only tagged types can be inherited from

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

32
Q

4 OO characteristics in Eiffel PL

A
  • 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

33
Q

what are methods called in Eiffel

A

routines

34
Q

what are instance variables called in Eiffel

A

attributes

35
Q

What are “features” in Eiffel

A

the routines and attributes of a class together

36
Q

7 inheritance characteristics of Eiffel

A
  • 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
37
Q

what is the “redefine” clause in Eiffel

A

defines an overridden feature

38
Q

what is the “rename” clause in Eiffel

A

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

39
Q

what is “design by contract” in Eiffel

A

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

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