Advertisement
teslariu

polimorfismo, getters, setters

Nov 14th, 2023
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. class Auto {
  2. // Atributos
  3. string color;
  4. string marca;
  5. int anioFabricacion;
  6.  
  7. // Métodos
  8. void acelerar(int v1){ // firma: void acelerar(int)
  9. velocidad = velocidad + v1;
  10. }
  11.  
  12. void acelerar(int v1, bool tieneNitro){ // firma void acelerar(int, bool)
  13. if {tieneNitro == False}{
  14. acelerar(v1);
  15. } else {
  16. acelerar(2*v1);
  17. }
  18. }
  19.  
  20. void acelerar(){ // void acelerar()
  21. velocidad = velocidad + 1;
  22. }
  23. }
  24.  
  25. #########_____________________________________________
  26.  
  27. 25 + 25 = 50 calculo
  28. 25 + x = ? --> cómputo --> funciones matematicas --> Computadora
  29.  
  30. Existen maquinas que pueden resolver autom funciones computables --> Maquinas de Turing
  31. ---> leng de programacion --> todos los leng de prog TURING COMPLETOS se
  32. basan en SOLO 3 ESTRUCTURAS logicas: condicional, bucle definido y bucle indefinido
  33.  
  34. if/else, for, while --> Python
  35.  
  36. switch case dowhile foreach repeat
  37.  
  38. #########_____________________________________________
  39.  
  40. Relaciones (de pertenencia):
  41. 1) Simples
  42. Clase: Motor Clase: Auto
  43. "Un auto <tiene solo un> motor" --> relacion simple, relacion uno a uno
  44.  
  45. 2) Relaciones multiples
  46. Clase: Auto Clase: Rueda
  47. "Un Auto tiene cuatro ruedas" --> "Un Auto <tiene de una a muchas> ruedas"
  48.  
  49. class Motor {
  50. string Marca
  51. int Potencia
  52. int Cilindrada
  53.  
  54. void Arrancar()
  55. void Detener()
  56. }
  57.  
  58. class Rueda {
  59. string Marca;
  60. string Dimensiones;
  61. string Tipo;
  62. }
  63.  
  64.  
  65. class Auto {
  66. string Marca;
  67. int AnioFabricacion;
  68. string Modelo;
  69. Motor motor;
  70. Collection<Rueda> ruedas;
  71.  
  72. // MÉTODOS
  73.  
  74.  
  75. }
  76.  
  77. class electrodomestico{
  78. String nombre;
  79. int voltaje;
  80. float precio;
  81. String origen;
  82.  
  83. encender(){
  84. }
  85.  
  86. usar(){
  87. }
  88.  
  89. apagar(){
  90. }
  91.  
  92. void aumentarprecio(int aumento){
  93. precio = precio + aumento
  94. }
  95.  
  96. void aumentarprecio(int aumento, bool preciosCuidados){
  97. if {preciosCuidados == False}{
  98. aumentarprecio(aumento);
  99. }
  100. }
  101.  
  102. bajarprecio(){
  103. }
  104. }
  105.  
  106.  
  107.  
  108. class alimento{
  109. String nombre;
  110. String origen;
  111. int calorias;
  112. String gusto;
  113. float precio;
  114. int temperatura;
  115.  
  116. void calentar(int temp){
  117. temperatura = temperatura + temp
  118. }
  119.  
  120. void calentar(int temp, bool helado){
  121. if {helado == False}{
  122. calentar(temp);
  123. }
  124. }
  125.  
  126. enfriar(){
  127. }
  128.  
  129. preparar(){
  130. }
  131. }
  132.  
  133.  
  134. ···············
  135. VISIBILIDAD: determina el alcance o scope de un atributo/operacion
  136. publico --> +
  137. privado --> -
  138. getters: metodos que sirven para leer el estado de un atributo
  139. setters: metodos que sirven para modificar el estado de un atributo
  140.  
  141. class Banco{
  142. private string nombre;
  143. private int cantidadDeEmpleados;
  144.  
  145. public void setNombre(string n){
  146. nombre = n;
  147. }
  148.  
  149. public void setCantidadDeEmpleados(int n){
  150. cantidadDeEmpleados = n;
  151. }
  152.  
  153. public string getNombre(){
  154. return nombre;
  155. }
  156.  
  157. public int getCantidadDeEmpleados(){
  158. return cantidadDeEmpleados;
  159. }
  160.  
  161. }
  162.  
  163.  
  164.  
  165. nombre_banco = Banco.getNombre()
  166. print(Banco.getNombre())
  167.  
  168.  
  169.  
  170. # explicar protected
  171.  
  172.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement