1/86
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
Object-Oriented Design (OOD)
a design philosophy focused on identifying good ADTs that model real-world objects and interactions
Object-Oriented Programming (OOP)
actual programs that use objects, variant behavior, inheritance, and dynamic binding
Object-Oriented Programming Language (OOPL)
a programming language that provides special features supporting OOP, such as inheritance, subtyping, and dynamic binding
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
what is the OO philosophy’s core ideas?
every program is a simulation of some real or conceptual world
according to OO philosophy, what improves program design?
designs whose structures mirror real-world structures and interactions
why should class names match real-world names?
it avoids ambiguity, improves understanding, and aligns code with the domain
in OOD, what forms the initial set of candidate ADTs?
real-world nouns, such as Books, Librarians, Patrons, Shelves, Catalogs
what is the purpose of identifying real-world relationships?
to capture behaviors and interactions that the program must simulate
what is the “principle of least surprise”?
designs should behave in ways users naturally expect, avoiding surprising or unnatural interactions
why does OOD improve communication with stakeholders?
is uses their terminology and mirrors their understanding of the domain
what are the three characteristics of an object?
identity, state, and behavior
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
what are messages and methods?
a message is a request sent to an object; a method is how the object responds internally
how can two objects respond differently to the same message?
they may have different methods implementing that message — key to variant behavior
what is a class?
a named collection of potential objects that share behavior and structure
who determines the method used for a message in most OOPLs?
the class to which the receiving object belongs
how do real-world objects differ from pre-OO data types?
real-world objects can belong to multiple categories simultaneously
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
what class relationship do OOPLs commonly support?
“is-a” or specialization/generalization relationships
what are the two OOPL mechanisms for representing “is-a” relationships?
inheritance and subtyping
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
what is a variant behavior?
the ability of different objects to respond differently to the same message
why can’t variant behavior be resolved at compile time?
the actual class of an object may not be known until runtime
what is dynamic binding?
choosing the correct method to execute at runtime based on the object’s actual class
what is static binding?
the function body to use is determined at compile time, based solely on declared type
what two features must an OOPL provide?
variant behavior (dynamic binding) + mechanisms to relate classes (inheritance)
what makes a program object-oriented?
it must actually use dynamic binding and objects that belong to multiple classes via inheritance or subtyping
why isn’t most Java/C++/Python code truly OOP?
many programs use classes as mere modules without inheritance or dynamic binding
what languages introduced encapsulated modules and classes for ADTs?
Modula, Modula-2, Ada
what languages introduced inheritance, subtyping, and dynamic binding?
Smalltalk, C++, Java
what is generalization?
class A is a generalization of class B if every object of B is also an object of A
what is specialization?
class B is a specialization of class A if everything true of A objects is also true of B objects
what does generalization mean at the specification/implementation level?
class B conforms to the public interface of class A
give an example of generaliztion/specialization
“transaction” is a general class; “check” and “deposit” are specializations
if every transaction has a date and amount, what do checks and deposits have?
they also must have a date and amount
if Transaction objects support apply(Balance), what much Checks and Deposits do?
also support apply(Balance)
what is inheritance?
class C inherits from class D if C has all of D’s data members and messages
what is the terminology for inheritance?
D is the base class; C is the derived or inheriting class
can a subclass add its own data members and methods?
yes
what is multiple inheritance?
a class inherits from more than one base class
why is multiple inheritance avoided in many languages?
it can cause data duplication issues (two copies of “name” or “uin”
which major OOP language disallows multiple inheritance?
Java (but allows multiple interfaces)
what is subtyping?
C is a subtype of D if a C value can be used wherever a D value is expected
what is the difference between inheritance and subtyping?
inheritance: concerns members (data/functions)
subtyping: concerns non-member use (substitutability)
can subtyping apply to non-member functions?
yes. a subtype object can be passed to any function expecting the supertype
what does Java use for pure subtyping separate from inheritance?
interfaces
what does class C : public Super mean in C++?
C inherits from Super
C is a subtype of Super
in C++, what happens if you declare a class with no base class?
it has no base class (unlike Java)
what keyword does Java use for inheritance?
extends
what does every Java class inherit from (directly or indirectly)?
java.lang.Object
why does Java form a huge inheritance tree compared to C++?
every class inherits from Object
what are examples of methods Java classes inherit from Object?
equals, clone, toString
what is overriding a function?
providing a new version of an inherited function in a subclass
what does NOT count as overriding?
changing parameter types
changing constness
overloading instead of overriding
can you still call the base-class version of an overriden function?
yes, using Base::foo()
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
can subclasses access private members of a base class?
no (both C++ and Java)
what are protected members?
accessible to inheriting classes but not to other external classes
which language has package visibility?
Java
what is Java’s package visibility?
members accessible to all classes in the same package
do C++ and Java handle protected the same?
yes— protected means subclasses can access the member
how are expressions typically represented?
as trees
what do internal nodes represent?
operators (+, *, /, -) applied to operand expressions
what do leaf nodes represent?
constants or cell references
what is copy semantics (in C++)?
assignment copies the value from one memory location to another
what is reference semantics (in Java/Python)?
assignment copies the address (reference) to a shared value
how are inherited data members implemented?
as an extension of the existing record; inherited fields keep the same byte offsets
how are function members stored?
as pointers stored at compiler-assigned offsets, similar to data members
what happens if a subclass does not override a function?
the inherited function pointer stays the same as the base class version
what happens if a subclass does override a function?
the constructor places the address of the new function body at the same offset
what is single dispatching?
only the type of the first parameter determines which method is called
what is multiple dispatching?
all parameters’ types are considered when selecting the method body
why is multiple dispatch rare?
it requires runtime table searching → slower and more complex
what is covariant inheritance?
parameter types move with the type of this (e.g., equals(Sub other))
what is contravariant inheritance?
parameter types move against the change in this, staying as the base type
which is the default in Java/C++?
contravariant inheritance
when does Java allow covariant overrides?
mainly in return types (overriding clone() )
what is downcasting?
casting from a superclass type to a subclass type
why is downcasting considered unsafe?
the object may not actually be an instance of the subclass
why are VTables used?
to store virtual function pointers in a shared structure per class instead of per object
where is the VTable pointer stored?
in a hidden data member inside each object at a fixed offset
what is the structure of a VTable?
a table (array) of function pointers indexed by the virtual function’s assigned index
what is a delegation?
an object delegates method behavior to an exemplar (prototype) object
how are new objects created under delegation?
by cloning the prototype
can cloned objects override methods?
yes — they can replace function pointers individually
which major language uses delegation?
JavaScript