代码拉取完成,页面将自动刷新
Socket.D 的协议实现,涉及了很多语言与平台。比如 javascript ,不能有同名的属性和方法,不能有同名的方数;像 python,习惯上用 _ 作命名间隔。
所以定义和申明个规范,为跨语言实现尽量风格统一提供参考。也可以让用户了解情况。
尽量少的定义,其它原则上参考第一个实现语言
setXxx():void
//指完全替换目标xxxSet():self
putXxx():void
//指部分替换目标xxxPut():self
addXxx():void
xxxAdd():self
getXxx()
xxxGet()
xxx()
//目前主要用在"实体"、"消息"、"帧"的接口上getXxxYyy
,xxxYyyGet
(常见风格)get_xxx_yyy
,xxx_yyy_get
(好像就 python 这风格)原 java 里可以:
public interface Demo{
String tag();
}
public class DemoDefault implements Demo{
String tag;
public Demo tag(String tag) { //这种风格,在 Builder 模式里算常见
this.tag = tag;
return this;
}
public String tag() { //它是主接口(优先简洁)
return this.tag;
}
}
在 js 里就没办法用了,需要改成:
//js
class DemoDefault {
_tag: string; //字段名不能与函数名同
tagSet(tag: stirng): Demo { //与主接口冲突,改成 tagSet 链式设置风格
this._tag = tag;
return this;
}
tag(): string { //它是主接口(优先简洁)
return this._tag;
}
}
//java
public class DemoDefault implements Demo{
String tag;
public Demo tagSet(String tag) { //与主接口冲突,改成 tagSet 链式设置风格
this.tag = tag;
return this;
}
public String tag() { //它是主接口(优先简洁)
return this.tag;
}
}
原 java 里可以:
public interface Demo{
Demo tag(String tag);
}
public class DemoDefault implements Demo{
String tag;
public Demo tag(String tag) { //它是主接口(优先简洁)
this.tag = tag;
return this;
}
public String tag() { //这种风格,在 Builder 模式里算常见
return this.tag;
}
}
在 js 里就没办法用了,需要改成:
//js
class DemoDefault implements Demo {
_tag: string; //字段名不能与函数名同
tag(tag: stirng): Demo { //它是主接口(优先简洁)
this._tag = tag;
return this;
}
getTag(): string { //与主接口冲突,改成 getTag 普通获取风格
return this._tag;
}
}
//java
public class DemoDefault implements Demo{
String tag;
public Demo tag(String tag) { //它是主接口(优先简洁)
this.tag = tag;
return this;
}
public String getTag() { //与主接口冲突,改成 getTag 普通获取风格
return this.tag;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。