ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:25.49KB ,
资源ID:8538992      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8538992.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(smalltalk超简明教程.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

smalltalk超简明教程.docx

1、smalltalk超简明教程Smalltalk 超简明教程Simberson 公司的David Buck 撰写的此文档是为C/C+/C#/Java 程序员介绍Smalltalk 的,而且已经得到他善意的许可而得以发布。如果你对正式的培训有兴趣请联系Simberson,咨询Smalltalk 培训。我听说很多Java 和C#程序员说他们看不懂Smalltalk 代码。Smalltalk 因为只有很少的语法,所以实际上它非常的简单。Smalltalk 的强大之处是它的环境和类库。本文意图通过代码对比,使Java 和C#程序员迅速理解Smalltalk。Copyright David Buck 20

2、05 临时变量Smalltalk 不需要变量的类型声明。临时变量通过两个竖线来定义JavaSmalltalkint a;char b;float c;| a b c | 赋值Smalltalk 使用 := 赋值JavaSmalltalka = 5;a := 5 消息Smalltalk 有三种消息类型形式参数例子一元运算符以小写字母开始的字符和数字0squared二元运算符连接符1+关键字使用多个冒号终结文字和数字字符1或者多个do:,between: and:传输一个或多个参数时,需要使用关键字消息。每一个参数前面需要添加关键字。Smalltalk不使用和;分割参数。例子:JavaSmallt

3、alk(); (10);(20,anotherAccount) (anotherAccount);myAccount getBalancemyAccount setBalance: 10myAccount transfer: 20 to:anotherAccountmyAccount = anotherAccount 运算优先级:一元运算符 (首先运算)二元运算符 (其次运算)关键字 (最后运算)在同等优先级下,运算是从左到右JavaSmalltalk3 + 5 * 6 myAccount transfer: 20 to:anotherAccount 常量Smalltalk 中整数类型,字符类

4、型,字符串类型,布尔类型,浮点数类型和双精度浮点数类型都是头等类对象。整数类型是无限精度的,会按需自动增长,而不会溢出(译者注:跟内存大小有关)。实际上,Smalltalk 中没有char 类型,byte 类型,short 类型,int 类型或者long 类型的相对应的类型。它们都是整数类型。JavaSmalltalk55012308r12300x7f16r7f3r21012 (你可以选择你想用的基数)200L2e-52e-52e-5d2d-5h$hu03A9Character value: 16r3A9hellohellocantcant 特定词Smalltalk 中,nil 引用一个真实的

5、对象,它是UndefinedObject 类的实例。true 是True类的实例,flase 是Flase 类的实例JavaSmalltalkthisselfnullniltruetruefalsefalsesuperbase (C#)super 方法返回JavaSmalltalkreturn value;value 级联JavaSmalltalkmyAccountdeposit: 20;transfer: 20 to: anotherAccount 注释JavaSmalltalk/* comment */etTime();endTime = new GregorianCalendar().g

6、etTime();Reservation class methods:newsuper new initializeReservation instance method:initializestartTime := Timestamp now.endTime := Timestamp now 块Smalltalk 称对象为块,它是包含可执行代码的对象。Java 中最相似的东西是匿名内部类,C# 中,跟匿名托管相类似。执行“块”无需参数,可以向它发送一个value 消息Smalltalk| block |block := 3 + 4.block value answer is 7块可以有参数,

7、每一个块参数的声明必须以冒号(:)开头,以竖线(|)表示参数列表的结束和块代码的开始。Smalltalk| block |block := :x :y | x * 2 + y.block value: 5 value: 3 answer is 13 语法结束到此为止,我们已经介绍了Smalltalk 所有的语法。其余的事情属于类库部分。你是否注意到我们是否忘记了某些事情if-then-else 或者while 循环Smalltalk 只使用块和普通的消息发送。 控制结构Smalltalk 没有在语言中内置控制结构。Smalltalk 使用向true 或者flase 对象发生消息作为替代。Jav

8、aSmalltalkif (tries 5)return Too many tries;elsereturn Trying again;tries 5ifTrue: Too many triesifFalse: Trying again注意表示从方法返回,不只是适用于块。 循环Smalltalk 使用块做循环。由于块是对象,所有我们可以先他们发生消息JavaSmalltalkint tries = 0;while (tries = 5) tryAgain();tries+;| tries |tries := 0.tries 500000.d := clients collect: :clien

9、t | client name.In the first case, we get a subcollection of those clients that are pretty rich. In the second, we get a collection of names (the original collection was a collection of clients).序列化抽象无须创建新的classEvery now and then, a reader will find code that looks likestuff value: x value: y value:

10、 zwhere the keywords are all “value:”. This clearly looks useless and bewildering to a non-Smalltalk reader. What is happening is that the programmer has (typically) created a new abstraction facility.Let me explain this fundamental capability that only Smalltalk supports with a challenge. Given tha

11、t we have already introduced the Client class earlier, suppose that we want a simple facility for looping through an individual clients parts; ., we want the loop to first give us the name, then the next time around, we want the age, and finally we want the address.The conventional solution in C+ an

12、d Java is to create a special stream class or enumerator, say called ClientIterator, with facilities to initialize it, to ask it if it is at the end, and, if not, to ask for the next object in the iterator. Then we can have a loop that sets up the iterator and, while not at the end, gets the next ob

13、ject and processes it. The advantage of the iterator is that it can provide its own variables for keeping track of where its at in the sequencing process; ., its not necessary to extend the Client class with “temporary” instance variables needed for iterating.An example piece of code that might make use of

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1