Skip to main content

プロトコル、インターフェース(protocol,interface)

Swift

protocol というのがそれっぽい

swift
protocol Protocol01 {
var member01: String { get set }
func method01()
}
struct Struct01: Protocol01 {
var member01: String
}

Generic にする場合は associatetype キーワードを使用

swift
protocol Protocol01 {
associatedtype T
var name: T { get set }
}

TypeScript

ある

ts
interface IReplyable {
reply(): string; // アクセス指定子は不要(つけられない)
}
class Dog implements IReplyable {
public reply(): string {
return "Bow";
}
}
const d = new Dog();
d.reply() // => "Bow"