0
Розглядається
design patterns, encapsulation concept: page 15
Hi,
In page 15 I see this phrase:
In page 15 I see this phrase:
That’s one of the reasons why the interfaces only care about the behaviors of objects, and why you can’t declare a field in an interface
My question is about TS language ( I'm studying it ). In TS when we define an interface we can declare fields
interface example { exampleField: string; exampleMethod ... }
In other languages I can´t do that ? or maybe you talk about other thing in regards to interfaces?
Служба підтримки клієнтів працює на UserEcho
Hi Bruno!
Thanks, that's a good question! In most languages I'm aware of, an interface can not contain fields. I think the main goal of interfaces in Typescript was to ensure type safety in a wild variety of possible JavaScript objects, rather than implement or enforce any of the OOP concepts.