I do not really understand, if anyone can draw for me, thank you.
class DisciplinaController extends GenericController<Disciplina>{
DisciplinaController() {
super(Disciplina.class)
}
}
I do not really understand, if anyone can draw for me, thank you.
class DisciplinaController extends GenericController<Disciplina>{
DisciplinaController() {
super(Disciplina.class)
}
}
In this class we are seeing the inheritance power associated with the use of generics: D. The GenericController class as the name suggests, is a generic controller. This means that it probably has methods for inserting, removing, updating, and listing elements that are basic to various controllers.
When using generics on it, the programmer is declaring that it "does not matter" what kind of element (or domain class) will be passed. For any type of element, the mode of action will be the same. The classes that extend the GenericController are specifying the element that will be handled.
In the case of the DisciplineController, the element is an object of the Discipline class. The use of generics is very cool, since it allows for this simplification in the code, since generic methods are treated in the generic class. Only specific methods need to be handled in classes that inherit from the generic class.
For example, let's suppose you had to create a method to listIntematicDisciplines. This method would be implemented in the DisciplineController class.
On the other hand, let's assume that we need a basic controller for teachers. It would just be necessary to create a TeacherController controller as follows:
class ProfessorController extends GenericController<Professor>{
ProfessorController() {
super(Professor.class)
}
}
Do you see how much more productive it is? You specify that you want to work with the Teacher class, passing it in the constructor, and specifying generics in the inheritance (extends GenericController). With this, you already "win" the implementation of the basic methods (insert, remove, update, lists) that are implemented in the GenericController class. If it were not for the use of generics, you would have to implement the basic methods on all new controllers every time:
class ProfessorController extends GenericController<Professor>{
ProfessorController() {
super(Professor.class)
}
void inserir() {/*Implementação do método*/}
void listar() {/*Implementação do método*/}
void remover() {/*Implementação do método*/}
}
Increasing your workload.
You can say few things.
You are declaring the class DisciplinaController
that inherits from GenericController<Disciplina>
which is a class that actually implements the driver mechanism that will be used in this class. This is a generic class, that is, it allows to work with several types of data checked and replaced in a static way. This means that in some places it is necessary to say what kind of data is going to be manipulated and in the class, instead of placing a fixed type, a generic type is placed in your writing, which is a kind of super variable, so when using the class it will be used with this type being passed in <>
.
Then there is the builder method statement. I know this because it has the same class name. It will be used to initialize the initial data of the class.
Within it is called the constructor of the class that inherited ( super()
is a language keyword that has this purpose), after all it needs to initialize the data of the other class. You are passing the Disciplina
class as a parameter to it. In case you are not initializing anything in the class itself, you may not really need it, but you can not tell just with this passage.
I do not know if this is the best way to learn, but it is explained. If you have more specific questions, ask.