3 - I ntroduction to S alltalk m The Design of Smalltalk...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Smalltalk 1 Introduction to Smalltalk Understanding Code
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Smalltalk 2 Documentation Smalltalk with Style – guidelines for writing code that complies with the common idioms of Smalltalk (on-line) Visualworks: Application Developers Guide Basic Libraries GUI Developers Guide
Background image of page 2
Introduction to Smalltalk 3 The Design of Smalltalk Smalltalk is really simple It was meant to be In its simplicity lies its greatness “We aim to make simple things simple and complex things possible.” —Alan Kay Foundations of Smalltalk Everything is an object Class -based inheritance All computation is done through message passing Modeled on English (e.g., periods end statements)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Smalltalk 4 Everything is an Object There are no exceptions to the object rule. Numbers, Booleans, etc. nil is an object (it is the only instance of ProtoObject, the root of the class inheritance tree) Even every class is an object Blocks and methods are objects too
Background image of page 4
Introduction to Smalltalk 5 Sample Code (factorial) (Integer) factorial “Returns the factorial of this integer. ‘5 factorial’ evaluates to 120.” self < 0 ifTrue: [ ^ self error: ‘Not defined’]. self = 0 ifTrue: [ ^ 1]. ^ self * (self - 1) factorial Return the value from the method
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Smalltalk 6 Sample Code (Integer) factorial “Returns the factorial of this integer. ‘5 factorial’ evaluates to 120.” self < 0 ifTrue: [^self error: ‘Not defined’] . self = 0 ifTrue: [^1] . ^self * (self - 1) factorial Blocks
Background image of page 6
Introduction to Smalltalk 7 Class-Based Inheritance Smalltalk is the Canonical Class-Based Object- Oriented Language Every object is an instance of some class All classes (except ProtoObject) have a parent class Parent is superclass Child is subclass Subclasses inherit behavior and structure from parent class
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Smalltalk 8 Class Hierarchy: SmallInteger Magnitude Character Date Number Float Fraction Integer SmallInteger – LargePositiveInteger » LargeNegativeInteger Time
Background image of page 8
Introduction to Smalltalk 9 Let’s Make a Class
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Introduction to Smalltalk 10 Message Passing All computation is triggered through message sends (sending a message to an object) Messages trigger methods Almost all of Smalltalk is <receiverObject> <message> 5 factorial 5 is the receiver object, factorial is the message 5 + 3 5 is the receiver object, + is the message, 3 is an argument How do we get from the message to the method?
Background image of page 10
Introduction to Smalltalk 11 Message Passing Answer: Through the Class Hierarchy Class determines behavior. Check the class of the receiver object for the method. If not
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 41

3 - I ntroduction to S alltalk m The Design of Smalltalk...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online