I'm just thinking about the concept of OO, which may seem rather trivial, but I don't know why I find it quite confusing.
In any case, I think, for example, if I have an Animal class and a Location class. And I allow one animal to be in one place at any time. So this seems like a 1 to 1 relationship. At the same time, I wish that the Animal and Location classes did not need some kind of bi-directional link, so that they were supported loosely coupled. If I have this:
class Animal {
private Location loc;
public Animal(int x, int y) {
loc = new Location(x,y);
}
public static newAnimal(Location[][] map, int x, int y) {
if(map[x][y] != null) {
return new Animal(x, y);
} else return null;
}
class Location extends Point {
public Location(int x, int y) {
super(x, y);
}
}
public static void main(String[] args) {
Location[][] map = new Location[10][10];
for(int x=0; x<10; x++) {
for(int y=0; y<10; y++) {
map[x][y] = new Location(x, y);
}
}
Animal dog = new Animal(2, 4);
Animal cat = new Animal(5, 6);
Animal horse = new Animal(2, 4);
Animal rabbit = Animal.newAnimal(map, 20, 50);
}
From this, I foresee 2 problems.
-, , , . 1-1 , . . , . , , . , , , , , . , , , .
, , , , - Animal. newAnimal() . , , Animal . .
Java . , .
.
!