AbstractVehicle using Time as class member
<p>I have made a class AbstractVehicle:</p>

<pre><code>package TruckingCompany;

public abstract class AbstractVehicle implements Movable
{
public Location location;
public Time time;
double direction;
public final int speed;
public AbstractVehicle(int speed)
{
    if(speed&lt;=0)
        speed=10;
    this.speed=speed;
}
public int getSpeed()
{
    return speed;
}
public void setLocation(Location location)
{
    this.location=location;
}
public void setTime(Time time)
{
    this.time=time;
}
public Location getLocation()
{
    return location;
}
public Time getTime()
{
    return time;
}
public void pointTo(Location where)
{
    direction=location.getDirectionFrom(where);
}
public void move(Time until)
{
    double dx,dy;
    int howLong;
    howLong=time.compareTo(until);
    dx=Math.sin(direction)*howLong/60;
    dy=Math.cos(direction)*howLong/60;
    if(howLong&gt;0)
    {
        time=new Time(until);
        location=new Location(location.getX()+dx,location.getY()+dy);
    }
}
public void move(double howFar)
{
    double dx,dy;
    dx=Math.sin(direction)*howFar;
    dy=Math.cos(direction)*howFar;
    location=new Location(location.getX()+dx,location.getY()+dy);
}
}
</code></pre>

<p>This is the interface Movable:</p>

<pre><code>package TruckingCompany;

public interface Movable 
{
public int getSpeed();
public void setLocation(Location location);
public void setTime(Time time);
public Location getLocation();
public Time getTime();
public void pointTo(Location where);
public void move(Time until);
public void move(double howFar);
}
</code></pre>

<p>This is a constant problem for me in Java and in other OOP languages like C++ .<br>
The problem is :  </p>

<ul>
<li>Is correct to make the class AbstractVehicle HAVE an object of type Time?  </li>
<li>Could it inherit from Time?  </li>
</ul>

<p>In procedural programming like C I could write a program and all I had to worry about was efficience, and a acode that make his job.<br>
But this case there are also conceptual errors, so there's a rule to know is what I'm doing is conceptually right? So for example someone could say that a Vehicle shouldn't have a Time object because all Vehicles can't have a different time.<br>
But I fail to get the criteria: when to put the HAVE relationship instead of inheriting, or when to don't use at all HAVE relationship and just corrdinate that field frome xternal classes.<br>
This case the Vehicle could not have an object of type Time, and could have just a method <code>move(double howLong)</code> indicating the minutes it had to move.I also could do it this way.
But why? And what's the criteria to choose?</p>
