1/22
Flashcards reviewing object-oriented programming concepts including equality design, hashing contracts, immutability, defensive copying, interfaces, subtyping, LSP, implementation inheritance, and composition.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Identity Equality (==)
A reference comparison that checks whether two object reference variables point to the exact same object location in memory.
Value Equality (.equals())
A logical comparison that checks whether two separate object instances contain matching internal content or field values.
Four Steps of designing .equals()
The standard sequence for implementing value equality: 1) self-check (this == o), 2) null and class guard (o == null || getClass() != o.getClass()), 3) cast (Money other = (Money) o), and 4) field comparison.
equals / hashCode Contract
The fundamental Java rule stating that if a.equals(b) is true, then a.hashCode() == b.hashCode() must also be true.

hashCode()
A method returning an integer hash value that determines which bucket or shelf an object goes into in hash-based collections before .equals() is used inside that bucket.

Immutability
A class design choice where object instances cannot be altered after creation, making them completely safe to share and alias across threads and data structures.
Copy-on-Change
A design pattern for immutable classes where state-modifying operations construct and return a brand-new object instance rather than mutating the existing one.
Defensive Copying
The practice of copying mutable objects when receiving them in constructors (copy IN) and when returning them in getter methods (copy OUT) to prevent internal state leaks.
Interface
A pure contract in Java that specifies method signatures declaring what an object can do, holding no instance state fields or method bodies.
implements
A Java keyword used by a class to declare that it fulfills an interface's contractual method signatures, enforced at compile time by javac.

Static Type
The type of a variable as declared in source code and checked by the compiler at compile time.
Dynamic Type
The actual type of the object instance referenced on the heap at run time.
Subtyping (Substitutability)
The principle that an object of a subtype can stand in anywhere its supertype or interface type is expected.
Comparable
A Java interface declaring int compareTo(T o) used to define a class's single, natural internal ordering.
Comparator
A Java interface declaring int compare(T a, T b) used to define custom, external sort orderings without modifying the target class.
Liskov Substitution Principle (LSP)
The principle that a subtype must be substitutable for its supertype in behavioral contracts and promises, not merely in method signatures.
Implementation Inheritance (extends)
A Java mechanism allowing a subclass to inherit and reuse state fields and method implementations from a superclass.
protected
An access modifier that allows access to members within the declaring class itself, its package, and any derived subclasses.

Constructor Chaining (super(…))
The mandatory execution of a superclass constructor at the beginning of a subclass constructor to initialize base layers first.

Method Overriding (@Override)
The practice of replacing a superclass method's implementation in a subclass using the exact same method signature, verified by the compiler via @Override.
Abstract Class
A class declared with the abstract keyword that contains a partial implementation (code and abstract method declarations) and cannot be directly instantiated.
Fragile Base Class Problem
An architectural flaw where unpromised internal changes in a superclass silently break the functionality of subclasses that relied on those internal implementation details.
Composition (HAS-A)
A design pattern where a class holds an instance of another object as a private field and delegates tasks to its public contract, avoiding the tight coupling of inheritance.