SLIDE 1 / 7

1. Abstract Class: The Incomplete Blueprint in Memory

An abstract class models a concept that cannot exist on its own in the real world (e.g. "Shape"). The compiler forbids new Shape(); only complete concrete subclasses can be instantiated in the Heap.

new Figura() ✕ ERROR DE COMPILACIÓN Figura is abstract; cannot be instantiated Heap: Instancias Concretas Válidas Circulo @0x91A0 radio = 5.0 | color = "Rojo" calcularArea() -> Math.PI * r * r Rectangulo @0x91B4 base = 4.0 | altura = 6.0 calcularArea() -> base * altura
Contract Inspection
Base Abstract Class: public abstract class Figura
Enforced Abstract Method: abstract double calcularArea()
Calculated Area Result: 78.54 u²
public abstract class Figura {
  private String color;
  public abstract double calcularArea(); // Sin cuerpo
}

2. Interfaces: The Universal Socket and Contract

An interface is a standardized port that decouples the service caller from the underlying implementation. The caller interacts only with Exportable without knowing whether data flows to PDF, Excel, or JSON.

Cliente ReporteServicio exportar() <<interface>> Exportable byte[] exportar(); Puerto universal USB DocumentoPDF implements Exportable ReporteExcel implements Exportable MensajeJSON implements Exportable
Format Socket
Connection Type: Exportable exp = new DocumentoPDF()
Generated Output: application/pdf (bytes[])
public void procesar(Exportable exp) {
  byte[] datos = exp.exportar(); // Desacople total
}

3. default Methods and Diamond Problem Resolution

Java 8 added default methods to evolve interfaces without breaking contracts. If a class implements two interfaces declaring conflicting default methods, the compiler mandates an explicit override resolution.

Interfaz Base Interfaz ImpresoraA default void imprimir() Interfaz ImpresoraB default void imprimir() Clase Multifuncion ImpresoraA.super.imprimir();
Conflict Resolution
Signature Clash: Ambas tienen default void imprimir()
Enforced Java Solution: ImpresoraA.super.imprimir();
@Override
public void imprimir() {
  ImpresoraA.super.imprimir(); // Desambiguación explícita
}

4. Inheritance vs Implementation: is-a vs can-do

A class can only extend one superclass ("is-a", shared identity and state), but it can implement infinite interfaces ("can-do", orthogonal capabilities).

abstract class Ave estado: plumaje, pico (is-a) class Pato extends Ave <<Volador>> can-do: volar() <<Nadador>> can-do: nadar()
Decision Matrix
Single Inheritance: extends (1 sola clase base)
Multiple Implementation: implements (N interfaces)
State in Memory: Variables de instancia solo en clases
public class Pato extends Ave 
    implements Volador, Nadador {
  // Hereda estado de Ave
  // Cumple contratos de Volador y Nadador
}

5. Namespaces and Packages: Collision Avoidance

Packages provide code geography and prevent name clashes using FQCN (Fully Qualified Class Name). Two classes named Item can coexist cleanly across separate packages.

package com.tienda.pedidos; class Item { ... } Artículo de catálogo pedido package com.tienda.envios; class Item { ... } Bulto físico embalado Desambiguación en Checkout.java import com.tienda.pedidos.Item; // Import simple para el más usado com.tienda.envios.Item bulto = new com.tienda.envios.Item(); // FQCN explícito
Package Visibility
Default Modifier (no keyword): package-private
Access: Visible en mismo paquete
From outside package: Invisible (encapsulado)
// package-private: solo visible para el paquete
class ValidadorInterno {
  void validar() { ... }
}

6. Modeling: Association, Aggregation, and Composition

Not everything is inheritance. Coupling between objects depends on their lifecycle in the Heap: Association (weak), Aggregation (shared), and Composition (strong cascade death).

1. Asociación (Uso mutuo) Conductor ────> Vehiculo Ciclos de vida independientes 2. Agregación (Rombo blanco ◇) Departamento ◇──── Profesor Si cierra depto, el profesor sobrevive 3. Composición (Rombo negro ◆) Factura ◆──── ItemFactura Si muere Factura, mueren sus ítems (GC)
Lifecycle Simulator
Professor State (Aggregation): VIVO en Heap (independiente)
InvoiceItem State (Composition): Intacto
// Composición: la Factura crea y posee sus items
public class Factura {
  private final Item[] items;
}

7. Challenge: Polymorphic Payment Simulator

Polymorphism in action: an abstract MedioPago class declares procesarPago(amount) and a Reembolsable interface exposes reembolsar(). Test each gateway to witness how the system reacts.

Tarjeta de Crédito (Visa/Mastercard) implements Reembolsable, Notificable Comisión: 3.5% | Proceso con pasarela bancaria Estado de la Transacción ($1,000.00) ✓ Pago APROBADO: $1,035.00 debitado instanceof Reembolsable: SÍ -> Reembolso habilitado
Payment Gateway
Base Amount: $1,000.00
Fee Calculated: +$35.00 (3.5%)
Allows Refund: SÍ
public void procesar(MedioPago m, double monto) {
  m.procesarPago(monto); // Abstracto
  if (m instanceof Reembolsable r) {
    r.emitirComprobante();
  }
}