Ejercicio 2 repeats the multiple-interface pattern from Ejercicio 1, this time in an entirely different domain — aquatic life. Two interfaces,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Jhaymayleth/unidad2_java/llms.txt
Use this file to discover all available pages before exploring further.
Nadador and Respirador, capture the distinct capabilities of a fish: moving through water and extracting oxygen from it. The Pez class implements both, demonstrating that the technique scales naturally to any set of behaviors you want to model.
The Interfaces
Nadador.java — anything capable of swimming:
Respirador.java — anything capable of breathing:
Volador and Cantante from Ejercicio 1. There is no shared hierarchy; they are simply separate contracts.
The Pez Class
Pez stores nombre (name) and tipo (species/type) and provides concrete implementations for both interface methods:
nadar() includes both the name and the type in its output (matching the volar() pattern in Ave), while respirar() uses only the name — the implementation detail that differentiates a fish’s respiration from, say, a land animal’s.
Usage — Ejercicio2.java
Multiple Views of the Same Object
Just asAve could be referenced as either a Volador or a Cantante, a Pez object can be referenced through either interface type, exposing only that interface’s methods to the caller:
Nadador objects doesn’t need to know or care whether each element is a Pez, a future Delfin, or any other swimming class.
Comparison with Ejercicio 1
| Aspect | Ejercicio 1 (Ave) | Ejercicio 2 (Pez) |
|---|---|---|
| Interfaces implemented | Volador, Cantante | Nadador, Respirador |
| Fields | nombre, especie | nombre, tipo |
| Domain | Avian / aerial | Aquatic |
| Pattern | class X implements A, B | class X implements A, B |