Created with <3 with dartpad.dev.
Created
November 7, 2023 03:00
-
-
Save leonus96/32533de26087c44b3ef7c4cca45e513b to your computer and use it in GitHub Desktop.
composición-objetos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Composición: | |
class Motor { | |
void encender() { | |
print('Runnn Runnn Runnn...'); | |
} | |
void apagar() { | |
print('Trtrt...'); | |
} | |
} | |
class Radio{ | |
void encender() { | |
print('Estas escuchando Ritmo...'); | |
} | |
void apagar() { | |
print('Tururin...'); | |
} | |
} | |
class Automovil { | |
Motor motor = Motor(); | |
Radio radio = Radio(); | |
void encender() { | |
motor.encender(); | |
} | |
void apagar() { | |
motor.apagar(); | |
radio.apagar(); | |
} | |
void encenderRadio() { | |
radio.encender(); | |
} | |
} | |
void main() { | |
final Automovil auto = Automovil(); | |
auto.encender(); | |
print('conduciendo...'); | |
auto.encenderRadio(); | |
print('sigo conduciendo...'); | |
auto.apagar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment