Commit efb5ae5b authored by Josue's avatar Josue

Patron Prototype

parent caa10466
Pipeline #320 canceled with stages
package org.example.designpatterns.prototype;
import org.example.designpatterns.prototype.model.CuentaAHImpl;
public class App {
public static void main(String[] args) {
CuentaAHImpl cuentaAhorro = new CuentaAHImpl();
cuentaAhorro.setMonto(200);
CuentaAHImpl cuentaAhorro2 = new CuentaAHImpl();
CuentaAHImpl cuentaClonada = (CuentaAHImpl) cuentaAhorro.clonar();
System.out.println(cuentaAhorro);
System.out.println(cuentaAhorro2);
System.out.println(cuentaClonada);
/*if(cuentaClonada != null)
System.out.println(cuentaClonada);
System.out.println(cuentaClonada == cuentaAhorro);*/
}
}
package org.example.designpatterns.prototype.interfaces;
public interface ICuenta extends Cloneable{
ICuenta clonar();
}
package org.example.designpatterns.prototype.model;
import org.example.designpatterns.prototype.interfaces.ICuenta;
public class CuentaAHImpl implements ICuenta {
private String tipo;
private double monto;
public CuentaAHImpl() {
tipo = "AHORRO";
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public double getMonto() {
return monto;
}
public void setMonto(double monto) {
this.monto = monto;
}
@Override
public ICuenta clonar() {
CuentaAHImpl cuentaAH = null;
try {
cuentaAH = (CuentaAHImpl) clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
return cuentaAH;
}
@Override
public String toString() {
return "CuentaAHImpl{" +
"tipo='" + tipo + '\'' +
", monto=" + monto +
'}';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment