0
审核中

design patterns, encapsulation concept: page 15

Bruno De angeli 3 年 前 更新人: Alexander 3 年 前 1

Hi,

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?

+1
审核中

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.

UserEcho 的客户支持