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

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

Introduction to Smalltalk 1 Introduction to Smalltalk Understanding Code

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

View Full Document
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
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)

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
Introduction to Smalltalk 8 Class Hierarchy: SmallInteger Magnitude Character Date Number Float Fraction Integer SmallInteger – LargePositiveInteger » LargeNegativeInteger Time
Introduction to Smalltalk 9 Let’s Make a Class

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

View Full Document
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?
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online