Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

1 Object Orientation James Brucker. 2 Smalltalk  Ahead of its time: consistent design and rich library.  Dynamic (like Lisp): variables have no specified.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
11. A bit of Smalltalk. © O. Nierstrasz P2 — A bit of Smalltalk 11.2 A bit of Smalltalk Overview  Some history  Smalltalk syntax & object model  The.
Principles of Object-Oriented Software Development The language Smalltalk.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Stéphane Ducasse«ChapterNr».1 Abstract Classes Should not be instantiated (abstract in Java) But can defined complete methods Defines a protocol common.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse8.1 Syntax and Messages The syntax of Smalltalk is simple and uniform, but it can look strange at first sight! Literals: numbers, strings,
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Stéphane Ducasse 1 The Taste of Smalltalk.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Summer Semester 2006.
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
S.Ducasse Stéphane Ducasse 1 A Taste of Smalltalk.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
03G-1 Everything is an Object Examining builtin classes All these are classes in Little Smalltalk:  Object  Class  Method  Block  Boolean True False.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
3. Standard Classes. © Oscar Nierstrasz ST — Standard Classes 3.2 Roadmap  Object  Numbers, Characters, Strings and Arrays  Variables  Blocks and.
3. Standard Classes. Birds-eye view © Oscar Nierstrasz ST — Introduction 1.2 Reify everything — by reifying its entire implementation model, Smalltalk.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
12. A bit of Smalltalk. © O. Nierstrasz P2 — A bit of Smalltalk 11.2 Roadmap  Some history  Smalltalk syntax & object model  The Smalltalk environment.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
Stéphane Ducasse4.1 A Taste of Smalltalk Two examples: –‘hello world’ –A Tomagoshi To give you an idea of: –the syntax –the elementary objects and classes.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
A TOUR OF RUBY 2011 ACM Class, Dong Xie. What is Ruby?  Dynamic programming language  Complex but expressive grammar  A core class library with rich.
3A-1 1 Introduction to Smalltalk History of Smalltalk The philosophy of Smalltalk:  “...we have a universe of well-behaved objects that courteously ask.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
CS 598 Scripting Languages Design and Implementation 7. Smalltalk 80.
Encapsulation and Data Abstraction Testing Applications in Smalltalk.
1 JavaScript in Context. Server-Side Programming.
Smalltalk for Unix & W i n d o w s Dennis Smith Cherniak Software Development Corporation.
Object-oriented Programming and Design 1 Polymorphism Poly => many Morph => shape Variables take on many shapes, or many classes of objects.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Chapter 12 Support for Object oriented Programming.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
Object-oriented programming and design 1 Object Identity = vs. == copying objects Value Object ValueWithHistory.
Squeak and Botkit-Port Jeff Forbes Joel Miller. Introduction ● Squeak is a pure OO language ● Based off of SmallTalk-80 – Designed at Xerox PARC by Alan.
+ Ruby and other programming Languages Ronald L. Ramos.
Smalltalk in a.NET World How to write a Smalltalk compiler without writing a VM John Brant
RUBY by Ryan Chase.
S.Ducasse 1 7. Understanding Metaclasses. S.Ducasse 2 Roadmap Metaclasses in 7 points Indexed Classes Class Instance Variables Class Variables Pool Dictionaries.
1 JavaScript in Context. Server-Side Programming.
Nathanael Schärli (SCG, University of Bern) and Andrew P. Black (CSE, Oregon Health & Science University) Nathanael Schärli (SCG, University of Bern) and.
3C-1 Identifiers Variables Literal Objects  Numbers  Characters  Strings Control Structure  Blocks  Conditionals  Loops Messages Defining New Classes.
Smalltalk Interpreted by Alan Frazier & Brian Sparks.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
3. Standard Classes. © Oscar Nierstrasz ST — Standard Classes 3.2 Roadmap  Object  Numbers, Characters, Strings and Arrays  Variables  Blocks and.
Programming Languages Programming languages are a compromise between spoken language and formal math. They allow humans to communicate with computers at.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
Stéphane Ducasse 1 Abstract Classes.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Object Oriented Programming (OOP) LAB # 8
Smalltalk – a Pure (and first) OOPL
Context.
Chapter 2 Squeak: Object-oriented design with multimedia applications
CS 331 Principles of Programming Languages
Introduction to Smalltalk
Let’s Talk about… Smalltalk.
Introduction to Smalltalk
CSE 3302 Programming Languages
Smalltalk on a Dime.
Presentation transcript:

Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses

Object-oriented programming and design 2 Smalltalk: Everything is an Object l Application objects: customer, inventory l GUI objects: button, text editor l Foundation: string, set, numbers, booleans l Tools: browser, debugger, compiler, GUI builder l Language implementation: class, method, context,

Object-oriented programming and design 3 Communicating with an Object All computation is done by objects. The only way to interact with an object is to "send a message" to it. Smalltalk has three kinds of syntax for sending a message. All messages have same implementation.

Object-oriented programming and design 4 Three Kinds of Message Syntax Unary messages aSalaryChange date Keyword messages earned at: date add: money Binary messages (worked - 40) max: 0

Object-oriented programming and design 5 One Way to Send a Message Object responds to message by looking in its class for a method with the same selector. If it doesn't find the method, it looks in its superclass. Repeat until it finds the method. If it never does, there is an error.

Object-oriented programming and design 6 Smalltalk in a nutshell l Classes have methods and variables. l Methods are a sequence of messages, assignments, returns. l Variables, literals, pseudovariables l Blocks l Metaclasses - classes have classes

Object-oriented programming and design 7 Smalltalk Expression Syntax Literals 3.675, 14, 'hello', #weight, $d, #( #foo 'bar' 92) Assignments and variables v := v + 1 Messages

Object-oriented programming and design 8 Smalltalk Expression Syntax Sequences. Blocks. x < y ifTrue: [z := x] ifFalse: [z := y]. paychecks do: [:each | each post] Cascades aSet add: #blue; add: #red

Object-oriented programming and design 9 Smalltalk Method Syntax Returns ^socialSecurity + federalTaxes + stateTaxes

Object-oriented programming and design 10 Variables in Smalltalk l blockArguments and temporaries l methodArguments and temporaries l instanceVariables Can be accessed only by the object's methods. l Globals, class variables Any method in the scope can access it Variable is object of class Association

Pseudovariables l nil l true, false l self l super l thisContext (in Squeak and VisualWorks, but not standard Smalltalk) Object-oriented programming and design 11

Summary l Classes are objects that define methods and variables of their instances. l Method is a sequence of message-sends, assignments, and return statements l Three kinds of syntax for messages, but one way of implementing them l Literals. Variables. Blocks. Object-oriented programming and design 12

Object-oriented programming and design 13 Message Lookup and Inheritance EmployeeTransaction has subclasses Paycheck, SalaryChange, and Timecard. EmployeeTransaction defines the instance variable date and the method: date ^date

EmployeeTransactiondate Paycheck check107/09/95 aPaycheck date

Object-oriented programming and design 15 Using Variables printOnCheckStream: aStream aStream cr; cr. aStream next: 40 put: (Character space). DateFormat print: date on: aStream. aStream cr....

Object-oriented programming and design 16 More variables test "PayrollSystem test" | payroll day1 ralph | day1 := Date newDay: 5 year: payroll := self new. ralph := Employee new name: 'Ralph Johnson'.

Object-oriented programming and design 17 (continued) ralph changeSalaryFor: day1 to: 20. payroll addEmployee: ralph. self employee: ralph hours: self aLittleOvertime starting: day1. ^payroll

Object-oriented programming and design 18 Initializing an Object Every object needs to be initialized. Uninitialized variables are nil. The initialization method often defines the type of a variable. Two methods: one class and one instance.

Object-oriented programming and design 19 Class Methods Class is an object. It can have methods, too. For class Date class newDay: dayInteger year: yearInteger ^self new day: dayInteger year: yearInteger

Object-oriented programming and design 20 Instance initializing method For class Date day: dayInteger year: yearInteger day := dayInteger. year := yearInteger

Object-oriented programming and design 21 Creating a Date Date newDay: 3 year: 1995 Date new day: 3 year: 1995 day: 3 year: day year

Object-oriented programming and design 22 Complete Smalltalk Expressions (method definition) message, assignment, sequence, block, return Variables, literals Classes, inheritance Class methods / instance methods Pseudovariables nil, true, false self, super, thisContext

Object-oriented programming and design 23 Smalltalk (the language) is trivial Complexity is class library. New language extensions fit in as well as numbers and control structures. Language extension => core language is trivial

Object-oriented programming and design 24 Implications class library = language extension => must know class library must standardize class library merging class libraries is like merging language extensions hard to make class libraries

Object-oriented programming and design 25 Applications l No programs, just objects l No “main” routine l Most applications create new classes, reuse a lot of existing ones