jeudi 9 juin 2016

Inheritance and Casting design

Good afternoon in my timezone.

    interface Transport
           ^
           |
-------------------------
Car     Bicycle     Airplane

Each of the classes implement some specific methods.

In some part of an EJB code, there is an service that get Transports from database,and it call the Car specifics methods.

Transport transport = getTrasport(...);
              Car car = (Car) transport;
              car.specificCarMethod(...);

Is there any good practice to avoid the Cast ?

Thanks in advance Best regards

Aucun commentaire:

Enregistrer un commentaire