Maxscript面向对象编程技术之封装与继承

来源:互联网 发布:如何设置电子狗数据 编辑:程序博客网 时间:2024/04/29 19:30

Oop 抽象的开始

提高代码维护性,扩展性,高效性

1、封装

2、继承

3、多肽

一、从代码中解读封装和继承

Struct Cat(Public--公开接口-- 初始化CatFn init = (messageBox("init the struct")Return true),-- 定义公有属性(成员)catColor = "black",catCount = 10,catSound = "mimi",-- 定义公有方法Fn PubFn =(messageBox("The cat count is "+this.catCount)This.PriFn()),Fn makeSound =(messageBox("cat sounds is "+this.catSound)),_init = init(),Private--私有接口-- 私有属性catName = "china cat",catOld = 999,-- 私有方法Fn PriFn =(messageBox("The cat name is "+this.catName)),-- 创建触发事件On create do(messageBox("The struct init is successful")),-- 克隆触发事件On clone do(messageBox("The struct has been cloned!")))struct Dog(Public-- 继承父类,先实例化dog = cat(),-- 获得父类属性dogColor = dog.catcolor,-- dog.dogName = dog.catName,--无法继承父类私有属性-- 继承父类方法dogSound = dog.makeSound,Fn dogSoundfn = (dogSound()messageBox("I am dog ,my sound is wawa")))dog = Dog()dog.dogColordog.dogSounddog.dogSoundfn()

二、关于多肽性

多肽,低耦合高质量代码,减少重复计算

还没找到如何实现,官方文档说道random,这确实是个不错的例子,同样的操作适合多种数据类型。

 

Maxscript 提供了现成的面向对象模块供使用,coder使用了面向对象,往往丢失了面向对象编程。

 

后续更多技术资料分享。。。

0 0