abstract methods of the same signature

Asked

Viewed 39 times

0

Hello, I am building for my college work a Webservice based on MVC architecture. For a better understanding of the problem I will explain a little how the classes are currently:

  • The abstract Model class has as one of the abstract methods the getTableName which returns the actual table name for the model.
  • This class uses the trait DML.
  • A trait DML depends on the method getTableName to inform the table the functions of select, Insert, update and delete.

My problem is that it is not possible to define the method getTableName as abstract in the trait and class that uses the trait and do not want to be dependent on the trait DML so that this method is abstract.

In short: I need the method getTableName be abstract in the trait because it needs it, but if the class that uses trait also needs this method to be abstract what can be done?

1 answer

1


If both class and trait need the same method, the error is in designing the modeling, since the trait is a horizontal inheritance.

You need to evaluate your model and define where it will stay and verify why there is a need for each of them to have this same method.

If it is not necessary for both to have, it is sufficient to define who should own the method.

Another suggestion would be the implementation of a base class that owned these characteristics.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.