DOC PREVIEW
UT Arlington CSE 3302 - Smalltalk

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

3/26/20081Administrative Issues• HW3 (due at March 18th)• Essay (due at May 1st)–ABET requirementLecture 22 –Prolog (III), Fall 2007CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20071q– you must get a passing score (37.5), otherwise you will receive Incomplete (I) for this course• MP2 (due at April 3rd)– released at March 20thCSE 3302 Programming LanguagesSmalltalk()Chengkai LiSpring 2008(cont.)Lecture 15 –OO Programming, Spring 20082CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 2008About method argumentsA>>f: xx := …Assignment to argument is not allowed.Why?Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20083• If you want to change x, send a message to x• If you just want to refer to another object, why don’t use a differ ent time?OO in Smalltalk• Everything is an Object (Classes are objects too)• Every object is an instance of a class (a class is an instance of its metaclass)• Every class has a superclass• Everything happens by messages.• Method lookup follows the inheritance chain.Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20084Object(Instance), Class, InheritanceMetaclassMetaclass classMagnitudeObjectProtoObjectIt lNumber classLecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20085SmallInteger classSmallInteger3IntegerNumberInteger classinheritanceinstance ofExamples“print it” and “inspect it”• 3 • 3 class•3 classclass3 class class• 3 class class class• 3 class class class class• 3 class class class class class• SmallInteger superclassLecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200863/26/20082Be wary of the confusing names in theBe wary of the confusing names in the following sev eral slides!!!Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20087Instance Variables• instance variable: the variables for instances– defined for the instances of a class– click “instance” in system browser– Inherited in subclass (cannot be redefined in subclass)each instance has its own copy–each instance has its own copyExample: Number subclass: #FractioninstanceVariableNames: 'numerator denominator'classVariableNames: ''poolDictionaries: ''category: 'Kernel‐Numbers'Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20088Instance Methods• instance methods:– defined for the instances of a class– click “instance” in system browser– Inherited in subclass (can be overridden in subclass)Example: Fraction>>+ Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 20089Class Instance Variables• class instance variables: the instance variable of a class (remember a class is an instance of the corresponding metaclass)– defined for a class– click “class” in system browserInherited in subclass (cannot be redefined in subclass)–Inherited in subclass (cannot be redefined in subclass)– The class and each subclass have their own copyExample: Very few in the system itself Float classinstanceVariableNames: '‘ (empty)Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200810Class Instance Variables (Example)Examples:?Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200811Class Methods• class methods: It is not called “class instance method”!– defined for a class– click “class” in system browser– Inherited in subclass (can be overridden in subclass)Example:Fraction class>>numerator: denominator:Fraction class>>oneLecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 2008123/26/20083Class Variables• Class Variable: it doesn’t pair with “class method”, which pairs with “class instance variable”– defined for both a class and its instances– click “instance” in system browser– Inherited in subclass (cannot be redefined in subclass)– There is only one copy! (shared by the class itself, all the subclasses, and all the instances of the class/subclasses)Example: Number variableWordSubclass: #FloatinstanceVariableNames: ''classVariableNames: 'E Epsilon Halfpi Infinity Ln10 Ln2 MaxVal MaxValLn MinValLogBase2 NaN NegativeInfinity NegativeZero Pi RadiansPerDegree Sqrt2 ThreePi Twopi'poolDictionaries: ''category: 'Kernel‐Numbers'Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200813Access• All data members are private– Instance variables: only directly accessible to the instance itself (inside instance methods)• Different instances have different copies of the instance variables– Class instance variables: only directly accessible to the class itself (inside class methods)Eh bl h it i f th l it ibl•Each subclass has its own copies of the class instance variables– Class variables: directly accessible to all the instances of the class and the class itself. (inside class methods and instance methods)• The same copy shared by all instances and subclasses• All methods are public (any object can send any message to any other object)– The private instance variables are accessible to outside through the methods.Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200814For Accessing Private Data:Setter and GetterExample:class Complexinstance variable real, imaginary• getterComplex>>real^real• setterComplex>>real: aNumberreal _ aNumber (remember _ means :=)Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200815Class Methods for Constructing New Instances• Example:class Complexclass methods:– Complex class>>real: aNumber1 imaginary: aNumber2| newComplex |newComplex _ super new.newComplexreal: aNumber1;imaginary: aNumber2.^ newComplex– Complex class>>new^ self real: 0 imaginary: 0Lecture 15 –OO Programming, Spring 2008CSE3302 Programming Languages, UT‐Arlington ©Chengkai Li, 200816Class Methods for Accessing Class Variables• Example:class Floatclass variable: Pi E Epsilon …class method:– Float class>>pi^Pi• Compare:– method real is defined in Complex, so


View Full Document

UT Arlington CSE 3302 - Smalltalk

Documents in this Course
Smalltalk

Smalltalk

11 pages

Syntax

Syntax

5 pages

Syntax

Syntax

5 pages

JAVA

JAVA

57 pages

Semantics

Semantics

41 pages

Control

Control

74 pages

Load more
Download Smalltalk
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Smalltalk and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Smalltalk 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?