2
I am developing a project using Ionic, and would like to better organize my classes.
Below is an example of how I would do with PHP:
<?php
trait comportamento {
public function ficarTriste() {
}
public function ficarFeliz() {
}
}
trait acao {
public function falar($texto) {
echo $texto;
}
public function olhar($endereco) {
return file_get_contents($endereco);
}
}
class serHumano {
comportamento;
acao;
//o resto do código
}
$humano = new serHumano();
$humano->ficarFeliz();
$humano->falar('oooi');
As I could do something like this using Typescript, I used PHP as an example because it’s the language I’m most familiar with. If I’m not mistaken, that’s called partial
.
Note: I did not put PHP in tags because the question is not the same, I just used it to demonstrate what I want.
then @bigown but I would not like to implement these methods in each class... they will be the same for all classes. The problem is that it will have many methods and I could not extend more than one class understand?
– Hiago Souza
I understand, but the language does not understand. It has how to do a delegation service, but with this example, nor does it compensate.
– Maniero
I get it, so let’s say Typescript doesn’t allow me to do that. Is that it? If it is just update the answer I mark as correct.
– Hiago Souza
@Hiagosouza more or less was already, I only gave an improvement
– Maniero