TypeScript Interface Vs Class

We have covered typescript interface and class in our previous tutorials.

Lets have a closer look at their differences:

ParameterTypeScript ClassTypeScript Interface
DefinitionTypeScript Class is a template which holds methods,variables and provides a skeleton to object.TypeScript Interface is a blueprint which will tell a deriving class what to implement.
Syntaxclass <className>{
interface <iName>{
Practical UsageTo design a skeleton of modules functionality wiseTo hide a complexity from external accessing resource and securing core logic
InstantiableWe can Instantiate class using its objectWe can not instantiate interface
InheritanceClass supports inheritance by extending other classSupports inheritance but can not implement other interfaces
FunctionsClass can have functions and function has complete definitionInterface can have function but it can not define it
ConstructorClass can have constructorNA
Access SpecifiersClass can public, private, protectedInterface uses only public access specifier.

Leave a Reply

Your email address will not be published. Required fields are marked *