What is the difference between defining a model as an interface or as a class in IONIC?

Asked

Viewed 742 times

1

I am a beginner in programming and my input language is Java.

Studying some projects with Ionic, I found one that used an interface to define a model, for example:

export interface Pessoa {
   nome: string;
   idade: number;
 }

Remember that the basic difference between a class and an interface is that the interface does not implement behaviors.

I know that Ionic is based on Typescript. Why adopt this practice?

I know that Typescript is not Java but as Java is my reference, where should be the methods of the class (or interface) Person in Ionic?

1 answer

1

In the link below there is a more in-depth tutorial on the issue.

https://showmethecode.com.br/typescript-classes-vs-interfaces/

But briefly, if you want a model that has only attributes and no method, use an interface. Otherwise, create a class to implement methods.

But remembering that even so, an interface can be extended in a class.

Browser other questions tagged

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