I am developing a small JAVA game and I have this problem about cohesion and coupling in OOP concept.
I have a class named Locations as below
public class Location {
private int positionX;
private int positionY;
public Location(int positionX, int positionY){
this.positionX=positionX;
this.positionY=positionY;
}
public void updateLocation(int positionX, int positionY){
this.positionX=positionX;
this.positionY=positionY;
}
public String getLocation(){
return (positionX+","+positionY);
}
public int getLocationX(){
return this.positionX;
}
public int getLocationY(){
return positionY;
}
public void setLocationX(int positionX){
this.positionX=positionX;
}
public void setLocationY(int positionY){
this.positionY=positionY;
}
}
And I have an interface named locatable as bellow
public interface Locatable {
public Location getPosition();
public void setPosition(Location position);
}
And a abstract class implementing the above interface as bellow
public abstract class GameObject implements Locatable{
protected String name;
protected Location position;
public GameObject(String name, Location position){
this.name=name;
this.position=position;
}
//------------- getter & setters for positions----------
@Override
public Location getPosition(){
return position;
}
@Override
public void setPosition(Location position){
this.position=position;
}
//------------------------------------------------------
//------------------------------------------------------
//------------- getter & setters for name ---------------
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
//------------------------------------------------------
//------------------------------------------------------
}
And a class that extends the above class
public class Lotus extends GameObject{
private int no_of_Petals=100;
public Lotus(String name,Location position){
super(name,position);
}
//-----getters & setters for no of petals --------
public void setNoOfPetals(int no_of_Petals){
this.no_of_Petals=no_of_Petals;
}
public int getNoOfPetals(){
return no_of_Petals;
}
//------------------------------------------------
//------------------------------------------------
}
So I am confused about whether the using Location class all over my code is not a good coding practice.Like is it tightly coupling ? or is it okay ? Please let me clarify this question as I am still learning about OOP. if you are going to down vote this question please provide a comment about where I am wrong before doing so..