Thursday, May 20, 2010

Sitting Stomach Feet Face

UML, UML

The post Aggregation and Composition raised another question (as always seems to happen , and I always give the debate to something else). The question comes on the side of the difference between Association and Aggregation in code. It argues that it is something conceptual, which is not represented in code. My answer is that it is 50% correct. Because, as I mentioned before (the label design is more about it), the Association came first, and aggregation would be a particular type of association. Ergo ... Aggregation "IS-A" partnership item for you! . First we see the UML diagram

Now let the code of the class Person (Note: Imagine that generics blogspot takes them as tags, so do not appear)

import java.util.List;
public
class Person {private String

name;
private String name;

private Photo photo;
private List lugaresFrecuentes;
List private communications;

public String getName () {return name;} public void
setNombre (String name) {this.name = name;}
getApellido public String () {return name;} public void
setApellido (String name) {this.apellido = name;}

/ / public
Photo Picture Association getFoto () {return photo;} public void
setFoto (Photo photo) {this.foto = photo;}

/ / public List getLugaresFrecuentes () {return lugaresFrecuentes;}
/ / public void setLugaresFrecuentes (List lugaresFrecuentes) {this.lugaresFrecuentes = lugaresFrecuentes;}

/ / public void
agregarLugar Aggregation (Place place) {
lugaresFrecuentes.add (location);
} public boolean
quitarLugar (Place place) {return
lugaresFrecuentes.remove (location);}

/ / public void
setComunicaciones Association (List communications) {
this.comunicaciones = communications;}

getComunicaciones public List () {return
communications;

}}


The main differences are that:
  1. The Aggregation are always collections or arrays ! Or something that serves as a container for "add" more than one object, but add one. (If no setter and would not add, add)
  2. The Aggregation has two methods : one for "add" one object to the list, and the other to remove the same.
  3. Aggregation can, of course, be the setter and getter methods , while the Association always have that place and get a reference variable of the same type of variable or class instance, in this List case.

Well, I hope I cleared any doubts, and to open:) Greetings.

0 comments:

Post a Comment