Bienvenida e Introducci贸n

1

驴Por qu茅 aprender Programaci贸n Orientada a Objetos?

2

驴Qu茅 resuelve la Programaci贸n Orientada a Objetos?

3

Paradigma Orientado a Objetos

4

Lenguajes Orientados a Objetos

5

Instalando Visual Studio Code

6

Diagramas de Modelado

7

Qu茅 es UML

Orientaci贸n a Objetos

8

Objetos

9

Abstracci贸n y Clases

10

Modularidad

11

Analizando Uber en Objetos

12

Reto 1: identificando objetos

Programaci贸n Orientada a Objetos. An谩lisis

13

Clases en UML y su sintaxis en c贸digo

14

Modelando nuestros objetos Uber

15

驴Qu茅 es la herencia?

16

Aplicando Herencia a nuestro proyecto Uber

17

Reto 2: analicemos un problema

Clases, Objetos y M茅todo Constructor

18

Creando nuestras carpetas iniciales para el curso

19

Definiendo clases en Java y Python

20

Definiendo Clases en JavaScript

21

Objetos, m茅todo constructor y su sintaxis en c贸digo

22

Objetos. Dando vida a nuestras clases en Java y Python

23

Declarando un M茅todo Constructor en Java y JavaScript

24

JavaScript orientado a objetos, lo m谩s nuevo

25

Declarando un m茅todo constructor en Python

Herencia

26

Aplicando herencia en lenguaje Java y PHP

27

Soluci贸n del reto de herencia en PHP

28

Aplicando herencia en lenguaje Python y JavaScript

29

Otros tipos de Herencia

30

Reto 4

Encapsulamiento

31

Encapsulamiento

32

Encapsulando atributos en Java

Polimorfismo

33

Generando polimorfismo en Java

34

Generando polimorfismo en PHP

Cierre del curso

35

El Diagrama UML de Uber

36

Conclusiones

37

Bonus: Qu茅 es la Programaci贸n Orientada a Objetos

Curso de Programaci贸n Orientada a Objetos: POO

Curso de Programaci贸n Orientada a Objetos: POO

Anah铆 Salgado D铆az de la Vega

Anah铆 Salgado D铆az de la Vega

Reto 4

30/37

Lectura

Nos queda la Jerarqu铆a Account pendiente.

...

Reg铆strate o inicia sesi贸n para leer el resto del contenido.

Aportes 540

Preguntas 15

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

o inicia sesi贸n.

Java:

Python:

Javascript:

Php:

Yo lo hice en Python

class Account:
    id = int
    name = str
    document = str
    email = str
    password = str

    def __init__(self, name, document):
        self.name = name
        self.document = document
from account import Account

class User(Account):
    def __init__(self, name, document, email, password):
        super.__init__(name, document, email, password)
from account import Account

class Driver(Account):
    def __init__(self, name, document, email, password):
        super.__init__(name, document, email, password)

Hecho en Java

Account

public class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(String name, String document, String email, String password){
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }
}

Driver

public class Driver extends Account{
    
    public Driver(String name, String document, String email, String password){
        super(name, document, email, password);
    }
}

User

public class User extends Account{
    
    public User(String name, String document, String email, String password){
        super(name, document, email, password);
    }
}

Mis resultados en JavaScript:

Account.js

class Account {

    constructor(name, document, email, password) {
        this.id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    printDataAccount() {
        console.log("The name: " + this.name);
        console.log("The document: " + this.document);
        console.log("The email: " + this.email);
        console.log("The password: " + this.password);
    }

}

User.js

class User extends Account {

    constructor(name, document, email, password) {
        super(name, document, email, password)
    }

}

Driver.js

class Driver extends Account {

    constructor(name, document, email, password) {
        super(name, document, email, password)
    }

}

index.js

var user = new User("Jose Ramirez", "INE001","[email protected]", "mypass");
user.printDataAccount();

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Herencia JS</title>
</head>
<body>
    <script src="Account.js"></script>
    <script src="User.js"></script>      
    <script src="index.js"></script>
    
</body>
</html>

Resultados en consola:

Me esto dando cuenta que todos est谩n haciendo los ejemplos en el lenguaje de preferencia, yo los he hecho en todos 馃槗馃槴

馃惐鈥嶐煉 Plasmando la soluci贸n en lenguaje Dart.

class Account {
  int id;
  String name;
  String document;
  String email;
  String password;

  Account({this.name, this.document});

  void printData(){
      print('Name: $name Document: $document');
  }
}
import 'account.dart';

class User extends Account{
  User({name, document}):super(name: name, document: document);
}
import 'account.dart';

class Driver extends Account{
  Driver({name, document}):super(name: name, document: document);
}
import 'user.dart';
import 'driver.dart';

void main() {
  User user = User(name: 'Andres Herrera', document: 'QWE234');
  user.printData();

  Driver driver = Driver(name: 'Andrea Ferran', document: 'ANDA765');
  driver.printData();
}

En Python creer铆a que debe ser as铆.

Clase Account

class Account:
    """
    account class
    """
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str
    
    def __init__(self,id,name,document,email,password):
        self.id         = id
        self.name       = name
        self.document   = document
        self.email      = email
        self.password   = password

Clase User

from account.py import Account 
class User(Account):
    """
    User Class
    """
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

Clase Driver

from account.py import Account 
class Driver(Account):
    """
    Driver Class
    """
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

Aqu铆 les muestro como seria en Ruby 馃槈

  class Account
    attr_accessor :id, :name, :document, :email, :password
  
    def initialize(id, name, document, email, password)
      self.id = id
      self.name = name
      self.document = document
      self.email = email
      self.password = password
    end
  end
  
  class Driver < Account
    def call_taxi
      puts "Llamaste al conductor: #{self.name} con documento #{self.document}"
    end
  end
  
  class User < Account
    def fullname
      puts "El nombre de este usuario es: " + self.name
    end
  end
  
  d = Driver.new(1, 'Ferdy', '98761', '[email protected]', 'pass$$')
  d.call_taxi # Llamaste al conductor: Ferdy con documento 98761       
  d.name # Ferdy

Python :

//main.py

from car import Car
from payment import Payment
from account import Account

if __name__ == "__main__":
    print("Hola Mundo")
    car = Car()
    car.license = "AMS234"
    car.driver = "Andres Herrera"
    print(vars(car))

    car2 = Car()
    car2.license = "QWE567"
    car2.driver = "Matha"
    print(vars(car2))

    paypal = Payment()
    paypal.id = 21231
    paypal.email = "[email protected]"
    print(vars(paypal))

    user = Account() 
    user.id = 21222
    user.name = "Sherk"
    user.document = "S21K"
    user.email = "[email protected]"
    user.password = "YoMeOp0ngo"
    print(vars(user))

//account.py
class Account:
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str

//user.py

from account import Account

class User(Account):
    def __init__ (self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

//driver.py

from account import Account

class Driver(Account):
    def __init__ (self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)


En Ruby:

account.rb

class Account
  attr_accessor :name, :document, :email, :password
  
  def initialize(name, document, email, password)
    @name = name
    @document = document
    @email = email
    @password = password
  end

  def print_data_account
    puts "Name: #{@name}"
    puts "Document: #{@document }"
    puts "Email: #{@email}"
    # Esto es para imprimir ****** en lugar del password ;-)
    puts "Password: #{'*' * @password.length}"
  end
end

user.rb

class User < Account
end

driver.rb

class Driver < Account
end

app.rb

user= User.new("Diego Camacho", "ID001","[email protected]", "password")

user.print_data_account

# Name: Diego Camacho
# Document: ID001
# Email: dcamacho@gmail.com
# Password: ********



Este seria el reto de la herencia para la familia account?

En mi caso PHP:

Account.php

<?php
class Account {
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;

    public function __construct($name, $document){
        $this->name = $name;
        $this->document = $document;
    }
}

User.php

<?php

require_once('Account.php');

class User extends Account{

    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
    
}

Diver.php

<?php

require_once('Account.php');

class Driver extends Account{

    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
}

codigo en python:

account:

class Account:
    id       = int
    name     = str
    document = str
    email    = str
    password = str

    def __init__(self, name,  document, email, password):
        self.name      = name
        self.document  = document
        self.email     = email
        self.password  = password

user:

from account import Account

class User(Account):
    typeUser = str

    def __init__(self, name, document, email, password, typeUser):
        super().__init__(name, document, email, password)
        self.typeUser = typeUser

driver:

from account import Account

class Driver(Account):
    typeDriver = str

    def __init__(self, name, document, email, password, typeDriver):
        super().__init__(name, document, email, password)
        self.typeDriver = typeDriver

User.php

<?php

require_once('Account.php');

class User extends Account {
  public function __construct($name, $document) {
    $this->name = $name;
    $this->document = $document;
  }
}

Driver.php

<?php

require_once('Account.php');

class Driver extends Account {
  public function __construct($name, $document) {
    $this->name = $name;
    $this->document = $document;
  }
}

PHP:

<?php
require_once('Account.php');

class AccountUser extends Account{
  public function __construct($name, $document, $email, $password){
    parent::__construct($name, $document);
    $this->email = $email;
    $this->password = $password;
  }
}
?>




<?php
require_once('Account.php');

class AccountDriver extends Account{
  public function __construct($name, $document, $email, $password){
    parent::__construct($name, $document);
    $this->email = $email;
    $this->password = $password;
  }
}
?>

Python

]

En Python:


Python:

User:

from account import Account

class User(Account):
    def __init__(self, name, document):
        super.__init__(name, document)

Driver:

from account import Account

class Driver(Account):

    driverLicense = str

    def __init__(self, name, document, driverLicense):
        super.__init__(name, document)
        self.driverLicense = driverLicense

[](

JS:

Java

public class Account {
  Integer id;
  String name;
  String document;
  String email;
  String password;

  public Account(String name, String document) {
    this.name = name;
    this.document = document;
  }

  public Account(String name, String document, String email, String password) {
    this.name = name;
    this.document = document;
    this.email = email;
    this.password = password;
  }

  public void printData() {
    System.out.println("Name: " + this.name);
    System.out.println("Document: " + this.document);
    System.out.println("E-mail: " + this.email);
  }
}
public class User extends Account {

  public User(String name, String document, String email, String password) {
    super(name, document, email, password);
  }

}
public class Driver extends Account {
  public String licenseNumber;

  public Driver(String licenseNumber, String name, String document, String email, String password) {
    super(name, document, email, password);
    this.licenseNumber = licenseNumber;
  }

Hola! Dejo mi aporte, hice el reto en Python y Java!

class Account:
    id           = int
    name         = str
    document     = str
    email        = str
    password     = str
    
    def __init__(self, name, document, email, password):
        self.name       = name
        self.document   = document
        self.email      = email 
        self.password   = password
from account import Account

class Driver(Account):
    
    def __init__(self, name, document, email, password):
        super().__init__(name, document, email, password)
from account import Account

class Driver(Account):
    
    def __init__(self, name, document, email, password):
        super().__init__(name, document, email, password)

class Driver extends Account{
    public Driver(String name, String document, String email, String password){
        super(name, document, email, password);
    }

}

class User extends Account{
    public User(String name, String document, String email, String password){
        super(name, document, email, password);
    }

}

class Account {

    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(String name, String document, String email, String password) {
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    void printUsersData() {
        System.out.println("User Name: " + name + " User Document: " + document + " User email: " + email + " User password: " + password);
    }

    void printDriverData() {
        System.out.println("Driver Name: " + name + " Driver Document: " + document + " Driver email: " + email + " Driver password: " + password);
    }
}

User.py

from account import Account

class User(Account):

    def __init__(self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

Driver.py

from account import Account

class Driver(Account):

    def __init__(self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

Esta es mi clase base:

class BaseClass:
    def __init__(self, id_: int):
        self.id_ = id_

El id es declarado como id_ porque id es una function reservada en Python.

Todas las dem谩s clases extiended la BaseClass

class Account(BaseClass):
    def __init__(self, id_: int, name: str, email: str, password: str):
        super().__init__(id_)

        self.name = name
        self.email = email
        self.password = password

    def __str__(self) -> str:
        return f'{self.name}, email: {self.email}'

En este caso, estamos creando un constructor con los datos pertinentes. El __str__ significa que cada vez que imprimimos un objeto Account, retorna el nombre y el email.


class Driver(Account):
    pass

class Passenger(Account):
    pass

Ya que el ID lo da la clase Account, no es necesario que las subclases Client y Driver tengan un ID. Las subclases pueden, por el momento, no tener atributos propios y solo usar los de la clase padre.

// java

class Client extends Account {
  public Client(String name, String document) {
    super(name, document);
  }
}

class Driver extends Account {
  public Driver(String name, String document) {
    super(name, document);
  }
}
# python (no olvidar importar la clase Account)

class Client(Account):
    def __init__(self, name, document):
        super().__init__(name, document)

class Driver(Account):
    def __init__(self, name, document):
        super().__init__(name, document)
// javascript

class Client extends Account {
  constructor(name, document) {
    super(name, document);
  }
}

class Driver extends Account {
  constructor(name, document) {
    super(name, document);
  }
}

JAVASCRIPT

  • Class Account
class Account
{
    constructor(name, document)
    {
        this.name = name;
        this.document = document;
        
        this.id;
        this.email;
        this.password;
    }

    setID(id) {
        this.id = id;
    }

    printAllAccountData() {
        console.log("ID: ", this.id);
        console.log("name: ", this.name);
        console.log("document: ", this.document);
    }

    printPublicAccountData() {
        console.log(this.name);
        console.log(this.document);
        console.log(this.email);
    }

    printPrivateAccountData() {
        console.log(this.id);
        console.log(this.password);
    }
}
  • Class User
class User extends Account
{
    constructor(account, email, pswd)
    {
        super(account, email, pswd);

        this.account = account;
        this.email = email;
        this.password = pswd;

    }

    printAllUserData() {
        console.log("----User Data----\r\n");
        this.account.printAllAccountData();
        console.log("email:\t", this.email);
        console.log("pswd:\t", this.password);
    }
}
  • Class Driver
class Driver extends Account
{
    constructor(account, email, pswd)
    {
        super(account);
        
        this.account = account;
        this.email = email;
        this.password = pswd;
    }

    printAllDriverData()
    {
        console.log("----Driver Data----\r\n");
        this.account.printAllAccountData();
        console.log("email:\t", this.email);
        console.log("pswd:\t", this.password);
    }

}
  • index.js
var Acc1 = new Account("Acc1", "30333444");
Acc1.setID("1");
var driver1 = new Driver(Acc1, "[email protected]", "pswd1")
driver1.printAllDriverData();

var Acc2 = new Account("Acc2", "30333555");
Acc2.setID("2");
var user1 = new User(Acc2, "[email protected]", "pswd2");
user1.printAllUserData();
  • Output
----Driver Data----
ID:  1
name:  Acc1
document:  30333444
email:	 acc1@gmail.com
pswd: 	 pswd1
----User Data----
ID:  2
name:  Acc2
document:  30333555
email:	 acc2@gmail.com
pswd :	 pswd2

Driver

User

main

account

Python

account. py

class Account: 
    id = int
    name = str
    document = str
    email = str 
    password = str

    def __init__(self, name, document):
        self.name = name
        self.document = document

Driver. py

from account import Account

class Driver(Account):
    email = str
    password = str

    def __init__(self, name, document, email, password):
        super().__init__(name, document)
        self.email = email
        self.password = password

User. py

from account import Account

class User(Account):
    email = str
    password = str

    def __init__(self, name, document, email, password):
        super().__init__(name, document)
        self.email = email
        self.password = password

23. Mis apuntes sobre: 鈥淩eto 4鈥

Les comparto la implementaci贸n del reto en mi lenguaje favorito por el momento, Javascript:

En primer lugar agregu茅 una funci贸n para que imprima los datos a la clase Account:
-1.Account.js

class Account{
    constructor(name, document){
        this.id;
        this.name = name;
        this.document = document;
        this.email;
        this.password;
    }
    printDataAccount(){
        console.log(this.name);
        console.log(this.document);
    }
}



-2.User.js

class User extends Account{
    constructor(name, document){
        super(name, document)
    }
}



-3.Driver.js

class Driver extends Account{
    constructor(name, document){
        super(name, document)
    }
}



As铆 de F谩cil! 馃槂

User

public class User extends Account {
    
    public User(String name, String document) {
        super(name, document);
    }
}

Driver

public class Driver extends Account {
    
    public Driver(String name, String document) {
        super(name, document);
    }
}

JAVA

  • Account
class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(String name, String document) {
        this.name = name;
        this.document = document;
    }
}
  • User
class User extends Account {
    public User(String name, String document) {
        super(name, document);
    }
}
  • Driver
class Driver extends Account {
    public Driver(String name, String document) {
        super(name, document);
    }
}

JAVASCRIPT

  • Account
class Account {
    constructor(name, document) {
        this.id;
        this.name = name;
        this.document = document;
        this.email;
        this.password;
    }
}
  • User
class User extends Account {
    constructor(name, document) {
        super(name, document)
    }
}
  • Driver
class Driver extends Account {
    constructor(name, document) {
        super(name, document)
    }
}

PHP

  • Account
<?php
class Account {
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;

    public function __construct($name, $document){
        $this->name = $name;
        $this->document = $document;
    }
}
?>
  • User
<?php

require_once('account.php');

class User extends Account {
    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
}
?>
  • Driver
<?php

require_once('account.php');

class Driver extends Account {
    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
}
?>

PYTHON

  • Account
class Account:
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str

    def __init__(self, name, document):
        self.name       = name
        self.document   = document
  • User
from account import Account

class User(Account):
    def __init__(self, name, document):
        super().__init__(name, document)
  • Driver
from account import Account

class Driver(Account):
    def __init__(self, name, document):
        super().__init__(name, document)
class User extends Account{
    public User(String name,String document){
        super(name, document);
    }
}

class Driver extends Account{
    public Driver(String name,String document){
        super(name, document);
    }
}```
class Driver extends Account
{
    public Driver(String name, String document){
        super(name, document);

    }
}```



class User extends Account
{
public User(String name, String document){
super(name, document);

}

}```

CODIGO en Account.php

<?php
  
  class Account{
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;
  
  public function __construct($name, $document, $email){
    $this->name = $name;
    $this->document = $document;
    $this->email = $email;
  }
  
  public function showDataUser(){
      echo "<h3>Informacion de Usuario:</h3>";
      echo "<br/> Nombres y Apellidos: " . $this->name;
      echo "<br/> Documento de Identidad: " . $this->document;
      echo "<br/> Correo: " . $this->email;
  }
}
?>

CODIGO en User.php

<?php

include_once('Account.php');

class User extends Account{
    public $foto;
    public $telefono;

    public function __construct($name, $document, $email, $foto, $telefono){
        parent:: __construct($name, $document, $email);
        $this->foto = $foto;
        $this->telefono = $telefono;
    }
}

?>

CODIGO en Driver.php

<?php

include_once('Account.php');

class Driver extends Account{
    public $foto;
    public $telefono;

    public function __construct($name, $document, $email, $foto, $telefono){
        parent::__construct($name, $document, $email);
        $this->foto = $foto;
        $this->telefono = $telefono;
    }

    public function showDataDriver(){
      echo "<h3>Informacion de Conductor:</h3>";
      echo "<br/> Nombres y Apellidos: " . $this->name;
      echo "<br/> Documento de Identidad: " . $this->document;
      echo "<br/> Correo: " . $this->email;
    }
}
?>

CODIGO en indexUser.php

<?php

require_once('Account.php');
require_once('User.php');
require_once('Driver.php');

$user1 = new User("Roberto Melchor", "84324823", "[email protected]", "foto1", "948598555");
$user1->showDataUser();

$user2 = new User("Segunda Torres", "82455553", "[email protected]", "foto2", "985984545");
$user2->showDataUser();

$conductor1 = new Driver("Carlos Dominguez", "85384383", "[email protected]", "fotoc1", "983459385");
$conductor1->showDataDriver();

$conductor2 = new Driver("Christian Oso", "64583758", "[email protected]", "fotoc2", "989379475");
$conductor2->showDataDriver();

?>

AL IMPRIMIR

Informacion de Usuario:

Nombres y Apellidos: Roberto Melchor
Documento de Identidad: 84324823
Correo: [email protected]

Informacion de Usuario:

Nombres y Apellidos: Segunda Torres
Documento de Identidad: 82455553
Correo: [email protected]

Informacion de Conductor:

Nombres y Apellidos: Carlos Dominguez
Documento de Identidad: 85384383
Correo: [email protected]

Informacion de Conductor:

Nombres y Apellidos: Christian Rodriguez
Documento de Identidad: 64583758
Correo: [email protected]

Implementando en PHP:

clase Account:

Clase User:

Clase Card:

Clase Index:


Manejando objetos con herencia (User,Card,Index):

JavaScript

User.js

class User extends Account
{
    constructor(id, name, document, email, password)
    {
        super(name, document)
        this.id = id;
        this.email = email;
        this.password = password;
    }

    printUserData()
    {
        console.log(this.name)
        console.log(this.id)
        console.log(this.email)
    }
}

Driver.js

class Driver extends Account
{
    constructor(id, name, document, email, password)
    {
        super(name, document)
        this.id = id;
        this.email = email;
        this.password = password;
    }

    printDriverData()
    {
        console.log(this.id)
        console.log(this.email)
    }
}

index.js

var driver1 = new Driver(10001,"Andr茅s Herrera", "AND123","[email protected]","passwordand01");

var uberX = new UberX("CVB123", driver1, "Chevrolet", "Spark");
uberX.passengers = 4;
console.log(uberX.brand);
console.log(uberX.model);
uberX.printDataCar();
driver1.printDriverData();

var user1 = new User(20001,"Andrea Ferra", "ANDA876","[email protected]","passworandy20");
user1.printUserData();

Soluci贸n de herencia en java

from account import Account


classUser(Account):
    def__init__(self, name, document):
        super().__init__(name, document)


from account import Account


classDriver(Account):
    def__init__(self, name, document):
        super().__init__(name, document)```

Clase Padre

public class Account {

    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(Integer id, String name, String document, String email, String password) {
        this.id         = Math.random();
        this.name       = name;
        this.document   = document;
        this.password   = password;
        this.email      = email;
    }
}

Clases Hijas

class User extends Account{
public User(Integer id, String name, String document, String email, String password){
super(id, name, document, password, email);
}
}

class Driver extends Account{
String nroLicencia;

public Driver(Integer id, String name, String document, String email, String password, String nroLicencia){
    super(id, name, document, password, email);
    this.nroLicencia = nroLicencia;
}
}

Aclaracion: me parecio importante agregar a los datos del conductor su nro de licencia de CONDUCIR, tengo entendido que license de la clase car es algo totalmente distinto.

class Account {
  constructor(name, document) {
    this.id;
    this.name = name;
    this.document = document;
    this.email;
    this.password;
  }
}

class User extends Account {
  constructor(id, name, document, email, password) {
    super(id, name, document, email, password);
  }
}

class Driver extends Account {
  constructor(id, name, document, email, password) {
    super(id, name, document, email, password);
  }
}



JavaScript 鉂わ笍

Mi soluci贸n para Java, JavaScript y Python. Perd贸n por la mala resoluci贸n.

account:

class Account:
    id          = int 
    name        = str
    document    = str
    email       = str
    password    = str

    def __init__(self,id,name,document,email,password):
        self.id = id
        self.name = name
        self.document = document
        self.email = email
        self.password = password

driver:

from account import Account

class Driver(Account):
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

user:

from account import Account

class User(Account):
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

main:

from account import Account
from car import Car
from UberX import UberX
from driver import Driver
from user import User

if __name__ == "__main__":
    print("Hola mundo")

    '''car = Car("AMS234", Account("Andres Herrera", "ANDA876"))
    print(vars(car))
    print(vars(car.driver))

    uberX = UberX("AMS234", Account("Andres Herrera", "ANDA876"),"nissan","sentra");
    print(vars(uberX))
    '''
    user1 = User(1,"Chris","AND123","[email protected]","12345678")
    driver1 = Driver(1,"Andres Herrera","WOW123","[email protected]","87654321")
    
    print(vars(user1))
    print(vars(driver1))

Salida:

脡sta es mi soluci贸n en Java:

public class Account
{
    Integer id;
    String nombre;
    String document;
    String email;
    String password;

    public Account(String nombre, String document)
    {
        this.nombre = nombre;
        this.document = document;
    }
}

public class User extends Account {
    float credito;
    
    public User(String nombre, String document, float credito)
    {
        super(nombre, document);
        this.credito = credito;
    }   
}

public class Driver extends Account{
    float calificacion;
    String tipo_auto;
    
    public Driver(String nombre, String document, float calificacion, String tipo_auto)
    {
        super(nombre, document);
        this.calificacion = calificacion;
        this.tipo_auto = tipo_auto;
    }  
}

PHP
Clase Account

<?php 

class Account{
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;

    public function __construct($name, $document){
        $this->name = $name;
        $this->document = $document;
    }

    public function printDataAccount(){
        echo "Nombre: ". $this->name."</br>";
        echo "N煤mero Id: ".$this->document."</br>";
        echo "Email: ".$this->email."</br>";

    }
}



?>

Clase Driver

<?php 

require_once('account.php');

class Driver extends Account{
    
    public function __construct($name, $document, $email, $password){

        parent::__construct($name, $document);
        $this->email = $email;
        $this->password = $password;
    }
}


?>

Clase User

<?php 

require_once('account.php');

class User extends Account{

    public function __construct($name, $document, $email, $password){
        parent::__construct($name, $document);
        $this->email = $email;
        $this->password = $password;
    }
}

?>

package CursoPOOUber.Java;

class Account {

Integer id;
String name;
String document;
String email;
String password;

public Account (String name,String document){
    this.name = name;
    this.document = document; 

}

void printDataAccount(){
    System.out.println("License: " + name + " Name Driver: " + document);
}

}

package CursoPOOUber.Java;

public class Driver extends Account{

public Driver(String name,String document){
    super(name,document);
}

}

package CursoPOOUber.Java;

public class User extends Account{

String nameUser;

public User(String name,String document,String nameUser){
    super(name,document);
    this.nameUser=nameUser;
}

}

**Javascript **



Python



Php



Java



Reto completado!!!

Mi aporte en Java

Java (Clase User)
![](

Comparto mi codigo en Python:

JAVASCRIPT

class Account{

    constructor(name, document, email, password){
        this.id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    printDataCar(){
        console.log(this.name);
        console.log(this.document);
        console.log(this.email);
    }
}```



class User extends Account{
constructor(name, document, email, password){
super(name, document, email, password);
}
}

class Driver extends Account{
    constructor(name, document, email, password){
        super(name, document, email, password);
    }
}```
var car = new Car("ABC123", new Account("Diego Celis", "987987"))
car.printDataCar();

var uberX = new UberX ("MNB654", new Account("Laura", "654321"), "Renault", "Twingo");
uberX.printDataCar();

var user = new User ("Lupe", "1245", "[email protected]", "123");
user.printDataCar();```

Me gustaria que escribieran los atributos de cada subclase para poder a帽adirlo al reto.

Excelente!

Reto realizado en python:
Account

class Account :
    id = int
    name = str
    document = str
    email = str
    password = str

    def __init__(self, name, document) :
        self.name = name
        self.document = document

User

from Account import Account

class User(Account):

    age = int
    address = str

    def __init__(self, name, document,age, address):
        super().__init__(name, document)
        self.age = age
        self.address = address

Driver

from Account import Account

class Driver(Account):

    age = int

    def __init__(self, name, document, age):
        super().__init__(name, document)
        self.age = age

main

from Car import Car
from User import *
from Driver import *

if __name__ == "__main__":
    print("Hola mundo")
    
    car = Car()
    car.driver = "Andres Herrera"
    car.license = "AMS123"
    print(vars(car))

    car2 = Car()
    car2.license = "AFKA29"
    car2.driver = "Toreto"
    print(vars(car2))

    user1 = User("Romelia Guzman","912834194",45,"Carrera 31 ")
    print(vars(user1))

    driver1 = Driver("Ernesto Perez", "123125", 15)
    print(vars(driver1)) 

Mi aporte en JS
Account.js

class Account{
    
    constructor(id, name, document, email, password) {
        this.id = id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    
    
}

Driver.js

class Driver extends Account{

    constructor(id, name, document, email, password){
        super(id, name, document, email, password);
    }     
     printDataDriver(){
        console.log("Id : " + this.id);
        console.log("Name : " + this.name);
        console.log("Document : " + this.document);
        console.log("Mail : " + this.email);
        console.log("Password : " + this.password);
     }  
}

User.js

class User extends Account{

    constructor(id, name, document, email, password){
        super(id, name, document, email, password);
    }   

    printDataUser(){
        console.log("Id : " + this.id);
        console.log("Name : " + this.name);
        console.log("Document : " + this.document);
        console.log("Mail : " + this.email);
        console.log("Password : " + this.password);
    }
}

Mi aporte en Java:
Account.java

class Account {
    Integer id;
    String name;    
    String document;    
    String email;    
    String password;    
    
    public Account(Integer id, String name, String document,  String email, String password){
        this.id         = id;
        this.name       = name;
        this.document   = document;
        this.email      = email;
        this.password   = password;
    }

    void printDataAccount(){
        System.out.println("---User Data--");
        System.out.println("id: " + id);
        System.out.println("name: " + name);
        System.out.println("document: " + document);
        System.out.println("email: " + email);
        System.out.println("password: " + password);
        System.out.println("-------------");
    }
}

Driver.Java

class Driver extends Account{

    public Driver(Integer id, String name, String document, String email, String password){
      super(id, name, document, email, password);
    }    
}

User.java

class User extends Account {
  
    public User(Integer id, String name, String document, String email, String password){
        super(id, name, document, email, password);
      }    
}

AMO Python 鉂わ笍

class Account:
    # Constructor de la clase Account
    def __init__(self, id, name, document, email, password):
        # Inicializamos las propiedades
        self.id = id
        self.name = name
        self.document = document
        self.email = email
        self.password = password


class User(Account):
    # Constructor de la clase User
    def __init__(self, id, name, document, email, password):
        # Llamamos al constructor de la clase padre para inicializar las propiedades comunes
        super().__init__(id, name, document, email, password)


class Driver(Account):
    # Constructor de la clase Driver
    def __init__(self, id, name, document, email, password):
        # Llamamos al constructor de la clase padre para inicializar las propiedades comunes
        super().__init__(id, name, document, email, password)
 

el driver lo hemos ido creando solo con nombre y documento, estos 2 par谩metros son obligatorias para la creaci贸n del objeto driver, p贸r eso est谩n dentro del constructor.
Al momento de crear las sub clases User y Driver hay que tener en cuenta que si colocamos en sus constructores todos los par谩metros ya no podremos crear una driver solo con nombre y documento, sino que sera obligatorio colocar todos estos datos introduciodos en el constructor. Por otra parte en el super() si deben ir todos los par谩metros que queremos que herede del Account

JAVA

class Account():
    def __init__(self, id, name, email, password):
        self.id = id
        self.name = name
        self.email = email
        self.password = password

class User(Account):
    def __init__(self, id, name, email, password, payment_method):
        super().__init__(id, name, email, password)
        self.payment_method = payment_method

class Drive(Account):
    def __init__(self, id, name, email, password, identif_doc, license):
        super().__init__(id, name, email, password)
        self.identif_doc = identif_doc
        self.license = license

Para 鈥淧ython鈥:
El c贸digo de la instructora no funcion贸, para que no arroje errores se requiere () en el super:

Ej. clase UberX:

from car import Car
class UberX(Car):
brand = str
model = str
def init(self, license, driver, brand, model):
super().init(license,driver)
self.brand = brand
self.model = model

Y su llamado en 鈥渕ain鈥 es:

uberX = UberX(license=鈥渓ic01鈥, driver= Account(鈥淎ndrea Herrera鈥,鈥淎NDA876鈥),brand=鈥渏aguar鈥,model=鈥渪c01鈥)

uberX.passegenger=4
print(vars(uberX))
print(vars(uberX.driver))

PYTHON

user.p

from account import Account
class   User(Account):
    def __init__(self, name, document):
        super().__init__(name, document)

driver

from account mport Account
class   User(Account):
    def __init__(self, name, document):
        super().__init__(name, document)

PHP

user.php

<?php 
require_once('account.php');
class User extends Account {
	public function __construct($name, $document){ // M茅todo Constructor de la clase
		parent::__construct($name, $document); // Aplicaci贸n de Herencia
	}
}
?>

driver.php

<?php 
require_once('account.php');
class Driver extends Account {
	public function __construct($name, $document){ // M茅todo Constructor de la clase
		parent::__construct($name, $document); // Aplicaci贸n de Herencia
	}
}
?>

Declaracion de las clases ACCOUNT,USER,DRIVER

ACCOUNT

USER

DRIVER

MAIN

RESULTADO CONSOLA

Reto 4 cumplido en Java: Me costo mucho ya que en alg煤n momento hab铆a visto Java, pero no con este tipo de enfoque.
Porfa: Si ven alg煤n error, ay煤denme!!! Deseo aprender mucho m谩s de Java.
![](

En java:

Python, mi primer lenguaje jejeje


Reto cumplido con Javascript:

Python

Java

PHP

JavaScript

from account import Account

class Driver(Account):

def __init__(self, id,name,document,email, password):
    super.__init__(id,name,document,email,password)

from account import Account

class User(Account):

def __init__(self, id,name,document,email, password):
    super.__init__(id,name,document,email,password)

Python:

Java:

JS:

PHP:

JavaSccript

Account


function Account(name, document) {
  this.id;
  this.name = name;
  this.document = document;
  this.email;
  this.password;
}

Driver

class Driver extends Account {
  constructor(name, document, email, password, yearExperience, address) {
    super(name, document)
    this.email = email;
    this.password= password;
    this.yearExperience = yearExperience;
    this.address = address;
  }

  imprimirFicha(){
    console.table({
                    name: this.name, 
                    document: this.document, 
                    email: this.email, 
                    password: this.password, 
                    yearExperience: this.yearExperience, 
                    address: this.address})
  }

}

var conductor = new Driver(鈥Daniel",鈥12388667鈥,"[email protected]鈥,鈥123鈥,5,鈥渟as stree av鈥);

conductor.imprimirFicha();

Informaci贸n resumida de esta clase
#EstudiantesDePlatzi

  • Debemos definir las clases para la herencia de Payment. Nuevamente, creamos los archivos para driver y user. 隆Creamos las clases correspondientes con sus atributos!

Captura.PNG

class Account {
	Integer id;
	String name;
	String document;
	String email;
	String password;
	public Account(String name,String document,String email, String password)
	{
		this.name = name;
		this.document = document;
		this.email = email;
		this.password = password;
	}
	
}

public class driver extends Account{
	Integer id;
	String name;
	String document;
	String email;
	String password;
	public driver(String name,String document,String email, String password)
	{
		super(name,document,email,password);
	}

}

public class User extends Account{
	Integer id;
	String name;
	String document;
	String email;
	String password;
	public User(String name,String document,String email, String password)
	{
		super(name,document,email,password);
	}
}

Es en estos casos que uno dice 驴Qu茅 estoy haciendo?, lo hice en python y aqui esta mi aporte, espero que un experto en el tema me diga si esta bien, esto de POO es muy confuso, no logro entenderlo del todo.

Saludos!!!

if name == 鈥main鈥:
print(鈥淗ola mundo!!鈥)
print("info User: ")
user = User(鈥淢aria la del barrio",鈥555555鈥,"[email protected]鈥,鈥渓askmfds鈥)
print(vars(user))

print("info Uber X: ")
car = UberX("AMS243", Account("Andres Herrera","AKSD123","[email protected]","93eijdf"),"Chevete","123")
print(vars(car))
print(vars(car.driver))
print("Model: " + car.model)
print("Brand: " + car.brand)

print("info Uber pool: ")

car2 = UberPool("QSD133", Account("Oscar","QWWER235","[email protected]","aklfjfr"),"Mazda","92348")
print(vars(car2))
print(vars(car2.driver))
print("Model: " + car.model)
print("Brand: " + car.brand)

JAVA 鉂わ笍

Account Class

class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(String name, String document) {
        this.name = name;
        this.document = document;
    }
}

Driver Class

public class Driver extends Account {

    public Driver(String name, String document, String email, String password) {
        super(name, document);
        super.email = email;
        super.password = password;
    }
}

User Class

public class User extends Account{

    public User(String name, String document, String email, String password) {
        super(name, document);
        super.email = email;
        super.password = password;
    }
}

Aqu铆 mi aporte al reto 4:

Java

Js

PHP

Python

Muchas gracias

Vamos por m谩s 馃槃.

Reto realizado en python:

class Accounts():
    id = int
    name = str
    document = int
    email = str
    password = str

    def __init__(self, id, name, document, email, password):
        self.id = id
        self.name = name
        self.document = document
        self.email = email
        self.password = password	
from Accounts import Accounts

class User(Accounts):
    def __init__(id, name, document, email, password):
        super().__init__(id, name, document, email, password)
from Accounts import Accounts

class Driver(Accounts):
    def __init__(id, name, document, email, password):
        super().__init__(id, name, document, email, password)```

Soy un poco nuevo en esto, si tienen algun sugerencia o consejo, los leo compa帽eros:)
C贸digo Account:

class Account {

    constructor(name, document, email, password) {
        this.id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }
    printDataAccount() {
        console.log(this.name)
        console.log(this.document)
        console.log(this.email)
        console.log(this.password)
    }
}

C贸digo User:

class User extends Account {
    constructor(name, document, email, password){
        super(name, document, email, password)
    }
}

C贸digo Driver:

class Driver extends Account {
    constructor(name, document, email, password){
        super(name, document, email, password)
    }
}

Mi Aporte en PHP

<package JAVA;

public class Driver extends Account{

    public Driver(String name, String document) {
        super(name, document);
        
    }
}


<code>

package JAVA;

public class User extends Account{

    public User(String name, String document) {
        super(name, document);
        
    }
    
}

python
from account import Account

class user(Account):

def __init__(self,name,document, email, password):
    super.__init__(name,document,email,password)

from account import Account

class driver(Account):

def __init__(self,name,document, email, password):
    super.__init__(name,document,email,password)

RESUMEN CLASE 30:
RETO 4

JAVASCRIPT

Index HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POO</title>
</head>
<body>
    <h1>RETO 4: Aplicando herencia en JavaScript</h1>
</body>
<script src="Account.js"></script>
<script src="Car.js"></script>
<script src="UberX.js"></script>
<script src="UberPool.js"></script>
<script src="UberBlack.js"></script>
<script src="UberVan.js"></script>
<script src="User.js"></script>
<script src="index.js"></script>
</html>

Index JavaScript

    var car = new Car("AW456", new Account("Andres Herrera", "QWE234"))
    car.passenger = 4;
    car.printDataCar();

    var uberX = new UberX("AS678", new Account("Andrea Ferran", "ANDA765"), "Chevrolet", "Spark")
    uberX.passenger = 4;
    uberX.printDataCar();

    var uberPool = new UberPool("REW123", new Account("Andrew Endwer", "LKJG789"), "Aston Martin", "Road")
    uberPool.passenger = 4;
    uberPool.printDataCar();

    var uberBlack = new UberBlack("LKJ5647", new Account("Ruben Visconcy", "FGD835"), "Ford", "Focus")
    uberBlack.passenger = 4;
    uberBlack.printDataCar();

    var uberVan = new UberVan("MDN012", new Account("Jhon Wizdou", "FTR691"), "Toyota", "Cross")
    uberVan.passenger = 4;
    uberVan.printDataCar();

    var user = new User("Pepe Lucho", "123458SC", "[email protected]", "ERUI12345!@#$")
    user.printDataUser();

User JavaScript

class User extends Account {
    constructor(name, document, email, password){
        super(name, document, email, password)
        this.email = email;
        this.password = password;
    }
    printDataUser() {
        console.log(this.name);
        console.log(this.document);
        console.log(this.email);
        console.log(this.password);
    }
}

Drive JavaScript

class Driver extends Account {
    constructor(name, document, email, password){
        super(name, document)
        this.email = email;
        this.password = password;
    }
    printDataDriver() {
        console.log(this.name);
        console.log(this.document);
        console.log(this.email);
        console.log(this.password);
    }
}