The Object-Oriented Paradigm

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/86

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

87 Terms

1
New cards

Object-Oriented Design (OOD)

a design philosophy focused on identifying good ADTs that model real-world objects and interactions

2
New cards

Object-Oriented Programming (OOP)

actual programs that use objects, variant behavior, inheritance, and dynamic binding

3
New cards

Object-Oriented Programming Language (OOPL)

a programming language that provides special features supporting OOP, such as inheritance, subtyping, and dynamic binding

4
New cards

why do intro programming books often misrepresent OOP?

they conflate OOD with OOP and confuse modularity with object orientation, because beginners rarely write programs with many classes

5
New cards

what is the OO philosophy’s core ideas?

every program is a simulation of some real or conceptual world

6
New cards

according to OO philosophy, what improves program design?

designs whose structures mirror real-world structures and interactions

7
New cards

why should class names match real-world names?

it avoids ambiguity, improves understanding, and aligns code with the domain

8
New cards

in OOD, what forms the initial set of candidate ADTs?

real-world nouns, such as Books, Librarians, Patrons, Shelves, Catalogs

9
New cards

what is the purpose of identifying real-world relationships?

to capture behaviors and interactions that the program must simulate

10
New cards

what is the “principle of least surprise”?

designs should behave in ways users naturally expect, avoiding surprising or unnatural interactions

11
New cards

why does OOD improve communication with stakeholders?

is uses their terminology and mirrors their understanding of the domain

12
New cards

what are the three characteristics of an object?

identity, state, and behavior

13
New cards

what is the “kick it” test?

a heuristic: if you could kick/touch/see it in the real world, it’s likely a good candidate for a class

14
New cards

what are messages and methods?

a message is a request sent to an object; a method is how the object responds internally

15
New cards

how can two objects respond differently to the same message?

they may have different methods implementing that message — key to variant behavior

16
New cards

what is a class?

a named collection of potential objects that share behavior and structure

17
New cards

who determines the method used for a message in most OOPLs?

the class to which the receiving object belongs

18
New cards

how do real-world objects differ from pre-OO data types?

real-world objects can belong to multiple categories simultaneously

19
New cards

what limitation of pre-OO languages does OOP overcome?

in pre-OO languages, a value can only belong to one type; OOP allows values to belong to multiple classes

20
New cards

what class relationship do OOPLs commonly support?

“is-a” or specialization/generalization relationships

21
New cards

what are the two OOPL mechanisms for representing “is-a” relationships?

inheritance and subtyping

22
New cards

why is “Museum is a Building” often incorrect in real applications?

not all museums are physically contained in buildings; the real-world hierarchy is not always simple

23
New cards

what is a variant behavior?

the ability of different objects to respond differently to the same message

24
New cards

why can’t variant behavior be resolved at compile time?

the actual class of an object may not be known until runtime

25
New cards

what is dynamic binding?

choosing the correct method to execute at runtime based on the object’s actual class

26
New cards

what is static binding?

the function body to use is determined at compile time, based solely on declared type

27
New cards

what two features must an OOPL provide?

variant behavior (dynamic binding) + mechanisms to relate classes (inheritance)

28
New cards

what makes a program object-oriented?

it must actually use dynamic binding and objects that belong to multiple classes via inheritance or subtyping

29
New cards

why isn’t most Java/C++/Python code truly OOP?

many programs use classes as mere modules without inheritance or dynamic binding

30
New cards

what languages introduced encapsulated modules and classes for ADTs?

Modula, Modula-2, Ada

31
New cards

what languages introduced inheritance, subtyping, and dynamic binding?

Smalltalk, C++, Java

32
New cards

what is generalization?

class A is a generalization of class B if every object of B is also an object of A

33
New cards

what is specialization?

class B is a specialization of class A if everything true of A objects is also true of B objects

34
New cards

what does generalization mean at the specification/implementation level?

class B conforms to the public interface of class A

35
New cards

give an example of generaliztion/specialization

“transaction” is a general class; “check” and “deposit” are specializations

36
New cards

if every transaction has a date and amount, what do checks and deposits have?

they also must have a date and amount

37
New cards

if Transaction objects support apply(Balance), what much Checks and Deposits do?

also support apply(Balance)

38
New cards

what is inheritance?

class C inherits from class D if C has all of D’s data members and messages

39
New cards

what is the terminology for inheritance?

D is the base class; C is the derived or inheriting class

40
New cards

can a subclass add its own data members and methods?

yes

41
New cards

what is multiple inheritance?

a class inherits from more than one base class

42
New cards

why is multiple inheritance avoided in many languages?

it can cause data duplication issues (two copies of “name” or “uin”

43
New cards

which major OOP language disallows multiple inheritance?

Java (but allows multiple interfaces)

44
New cards

what is subtyping?

C is a subtype of D if a C value can be used wherever a D value is expected

45
New cards

what is the difference between inheritance and subtyping?

  • inheritance: concerns members (data/functions)

  • subtyping: concerns non-member use (substitutability)

46
New cards

can subtyping apply to non-member functions?

yes. a subtype object can be passed to any function expecting the supertype

47
New cards

what does Java use for pure subtyping separate from inheritance?

interfaces

48
New cards

what does class C : public Super mean in C++?

  • C inherits from Super

  • C is a subtype of Super

49
New cards

in C++, what happens if you declare a class with no base class?

it has no base class (unlike Java)

50
New cards

what keyword does Java use for inheritance?

extends

51
New cards

what does every Java class inherit from (directly or indirectly)?

java.lang.Object

52
New cards

why does Java form a huge inheritance tree compared to C++?

every class inherits from Object

53
New cards

what are examples of methods Java classes inherit from Object?

equals, clone, toString

54
New cards

what is overriding a function?

providing a new version of an inherited function in a subclass

55
New cards

what does NOT count as overriding?

  • changing parameter types

  • changing constness

  • overloading instead of overriding

56
New cards

can you still call the base-class version of an overriden function?

yes, using Base::foo()

57
New cards

if class B overrides foo(), what happens when you call b.foo() vs b.A::foo()?

  • b.foo() → B’s version

  • b.A::foo() → A’s version

58
New cards

can subclasses access private members of a base class?

no (both C++ and Java)

59
New cards

what are protected members?

accessible to inheriting classes but not to other external classes

60
New cards

which language has package visibility?

Java

61
New cards

what is Java’s package visibility?

members accessible to all classes in the same package

62
New cards

do C++ and Java handle protected the same?

yes— protected means subclasses can access the member

63
New cards

how are expressions typically represented?

as trees

64
New cards

what do internal nodes represent?

operators (+, *, /, -) applied to operand expressions

65
New cards

what do leaf nodes represent?

constants or cell references

66
New cards

what is copy semantics (in C++)?

assignment copies the value from one memory location to another

67
New cards

what is reference semantics (in Java/Python)?

assignment copies the address (reference) to a shared value

68
New cards

how are inherited data members implemented?

as an extension of the existing record; inherited fields keep the same byte offsets

69
New cards

how are function members stored?

as pointers stored at compiler-assigned offsets, similar to data members

70
New cards

what happens if a subclass does not override a function?

the inherited function pointer stays the same as the base class version

71
New cards

what happens if a subclass does override a function?

the constructor places the address of the new function body at the same offset

72
New cards

what is single dispatching?

only the type of the first parameter determines which method is called

73
New cards

what is multiple dispatching?

all parameters’ types are considered when selecting the method body

74
New cards

why is multiple dispatch rare?

it requires runtime table searching → slower and more complex

75
New cards

what is covariant inheritance?

parameter types move with the type of this (e.g., equals(Sub other))

76
New cards

what is contravariant inheritance?

parameter types move against the change in this, staying as the base type

77
New cards

which is the default in Java/C++?

contravariant inheritance

78
New cards

when does Java allow covariant overrides?

mainly in return types (overriding clone() )

79
New cards

what is downcasting?

casting from a superclass type to a subclass type

80
New cards

why is downcasting considered unsafe?

the object may not actually be an instance of the subclass

81
New cards

why are VTables used?

to store virtual function pointers in a shared structure per class instead of per object

82
New cards

where is the VTable pointer stored?

in a hidden data member inside each object at a fixed offset

83
New cards

what is the structure of a VTable?

a table (array) of function pointers indexed by the virtual function’s assigned index

84
New cards

what is a delegation?

an object delegates method behavior to an exemplar (prototype) object

85
New cards

how are new objects created under delegation?

by cloning the prototype

86
New cards

can cloned objects override methods?

yes — they can replace function pointers individually

87
New cards

which major language uses delegation?

JavaScript