So, I have this lecture and I'm preparing for a test. I have to write code so that my code passes each Junit test. One thing I always dont know how to figure out is, when should I use a interface or subclasses...
Could someone please tell me how can I decide which to use based on the Junit tests?
I have a train, in with there are two types of train: TGV and Pendular
P.S I know the test name explicitly says subclass, but ignore that...
public class RailRoadTests {
@Test
public void testTrain() {
Train c1 = new Train("Regional");
assertEquals("Regional", c1.getName());
Train c2 = new Train("Intercidades");
assertEquals("Intercidades", c2.getName());
}
@Test
public void testSubclassesTrain() {
Train tgv = new TGV("Speeder");
assertEquals("Speeder", tgv.getNome());
Train pendular = new Pendular("Alfa Pendular");
assertEquals("Alfa Pendular", pendular.getNome());
}