La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

1 Ingeniería del Software Colecciones de objetos  Descripción general  Patrón iterador  Iteradores en Java: enumeration  Patrón diccionario  Diccionarios.

Presentaciones similares


Presentación del tema: "1 Ingeniería del Software Colecciones de objetos  Descripción general  Patrón iterador  Iteradores en Java: enumeration  Patrón diccionario  Diccionarios."— Transcripción de la presentación:

1 1 Ingeniería del Software Colecciones de objetos  Descripción general  Patrón iterador  Iteradores en Java: enumeration  Patrón diccionario  Diccionarios en Java: hash

2 2 Ingeniería del Software Colecciones de objetos  Contexto:  Necesidad de acceder individualmente a objetos de una colección  Problema:  Se quiere acceder secuencialmente a todos los objetos de una colección  Solución:  Quitar la responsabilidad del acceso y recorrido del objeto agregado y asignarla a una nueva clase de objetos que llamaremos iterador  Beneficios  Uniformizar el acceso

3 3 Ingeniería del Software Patrón Iterador Venta fecha: fecha hora: hora consta 1..* referencia LineaVenta cantidad: entero Producto cp: código descripción: texto precio: real * Agrega muchos objetos LineaVenta

4 4 Ingeniería del Software Diagrama de secuencia: TerminarVenta  Representación de alto nivel, independiente del lenguaje :TPV terminarVenta() :Venta terminar() importe total() :LineaVenta:Producto subtotal() precio() *

5 5 Ingeniería del Software Código Java TerminarVenta: TPV package TPV; import java.util.*; class TPV { private Catalogo catalogo; private Venta venta;... public float terminarVenta () { venta.terminar(); return (float) venta.total(); }

6 6 Ingeniería del Software Código Java TerminarVenta: Venta package TPV; import java.util.*; class Venta { private Vector lineaVenta = new Vector(); private Date fecha = new Date(); private boolean estaTerminada = false; private float totalVenta = 0;... public void terminar () { estaTerminada = true; } public float total() { float total = 0; enumeration e = lineaVenta.elements(); while (e.hasMoreElements()) { total += ( (LineaVenta) e.nextElement() ).subtotal(); } totalVenta = total; return total; }

7 7 Ingeniería del Software Patrón diccionario Venta fecha: fecha hora: hora consta 1..* referencia LineaVenta cantidad: entero Producto cp: código descripción: texto precio: real * Una LineaVenta referencia un solo producto

8 8 Ingeniería del Software Diagrama de secuencia: AñadirProducto :TPV añadirProducto(cp, c) :Venta agregarLV(p, c) :LineaVenta crear(p, c) :Catálogo producto(cp) :Producto obtener(cp) p

9 9 Ingeniería del Software Código Java AñadirProducto: TPV package TPV; import java.util.*; class TPV { private Catalogo catalogo; private Venta venta;... public void añadirProducto (int cp, int cantidad) { Producto p = catalogo.producto(cp); venta.agregarLV(p, cantidad); }

10 10 Ingeniería del Software Código Java AñadirProducto: Catalogo package TPV; import java.util.*; public class Catalogo { private Hashtable DProducto = new Hashtable(); public Catalogo() { catalogo c = new producto(100, 2, “producto 100”); catalogo.put(new Integer(100), c); catalogo c = new producto(200, 1, “producto 200”); catalogo.put(new Integer(200), c); } public producto producto (int cp) { return (producto) catalogo.get(new Integer (cp)); }

11 11 Ingeniería del Software Código Java AñadirProducto: Producto package TPV; public class Producto { private int cp = 0; private float precio = 0; private String descripcion = “”; public producto (int cp, float precio, String descripcion) { this.cp = cp; this.precio = precio; this.descripcion = descripcion; }... }

12 12 Ingeniería del Software Código Java AñadirProducto: Venta package TPV; import java.util.*; class Venta { private Vector lineaVenta = new Vector(); private Date fecha = new Date(); private boolean estaTerminada = false; private float totalVenta = 0;... public void agregarLV (producto p, int cantidad){ lineaVenta.addElement(new LineaVenta(p,cantidad)); }

13 13 Ingeniería del Software Código Java AñadirProducto: LineaVenta package TPV; class LineaVenta { private int cantidad; private Producto producto;... public LineaVenta (producto p, int cantidad) { this.producto = p; this.cantidad = cantidad; }


Descargar ppt "1 Ingeniería del Software Colecciones de objetos  Descripción general  Patrón iterador  Iteradores en Java: enumeration  Patrón diccionario  Diccionarios."

Presentaciones similares


Anuncios Google