You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
626 B
30 lines
626 B
package patronComposite;
|
|
import java.util.ArrayList;
|
|
|
|
public class Compuesto extends Componente {
|
|
private ArrayList<Componente> hijos = new ArrayList<Componente>();
|
|
|
|
public Compuesto(String nombre) {
|
|
super(nombre);
|
|
}
|
|
|
|
public void add(Componente c) {
|
|
hijos.add(c);
|
|
}
|
|
|
|
public void Eliminar(Componente c) {
|
|
hijos.remove(c);
|
|
}
|
|
|
|
public Componente ObtenerHijo(int profundidad) {
|
|
return hijos.get(profundidad);
|
|
}
|
|
|
|
public void Operacion() {
|
|
for(int i = 0; i<hijos.size(); i++) {
|
|
System.out.println(nombre + " hijo: " + i);
|
|
Componente c = ObtenerHijo(i);
|
|
c.Operacion();
|
|
}
|
|
}
|
|
}
|
|
|