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

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使用了面向对象,往往丢失了面向对象编程。

 

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

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值