Oop 抽象的开始
提高代码维护性,扩展性,高效性
1、封装
2、继承
3、多肽
一、从代码中解读封装和继承
Struct Cat
(
Public --公开接口
-- 初始化Cat
Fn 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.dogColor
dog.dogSound
dog.dogSoundfn()
二、关于多肽性
多肽,低耦合高质量代码,减少重复计算
还没找到如何实现,官方文档说道random,这确实是个不错的例子,同样的操作适合多种数据类型。
Maxscript 提供了现成的面向对象模块供使用,coder使用了面向对象,往往丢失了面向对象编程。
后续更多技术资料分享。。。