Administrative Issues Lecture 22 – Prolog (III), Fall 2007 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, 2007 1 HW3 (due at March 18 th ) Essay.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Basic Object-Oriented concepts. Concept: An object has behaviors In old style programming, you had: –data, which was completely passive –functions, which.
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Inheritance.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Inheritance Inheritance Reserved word protected Reserved word super
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Language Issues for Inheritance CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.3 © Mitchell Wand, This work is licensed under a Creative.
CSE341: Programming Languages Lecture 22 Multiple Inheritance, Interfaces, Mixins Dan Grossman Fall 2011.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
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.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
CS 106 Introduction to Computer Science I 04 / 21 / 2010 Instructor: Michael Eckmann.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
Inheritance using Java
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Object-Oriented Programming Lecture 13 – OO Programming, Spring CSE3302 Programming Languages,
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CSCI-383 Object-Oriented Programming & Design Lecture 19.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Inheritance Chapter 10 Programs built from objects/instances of classes An O.O. approach – build on earlier work. Use classes in library and ones you have.
Objects & Dynamic Dispatch CSE 413 Autumn Plan We’ve learned a great deal about functional and object-oriented programming Now,  Look at semantics.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Smalltalk (cont.) Lecture 16 – OO Programming, Spring CSE3302 Programming Languages, UT-Arlington.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Constructors & Garbage Collection Ch. 9 – Head First Java.
S.Ducasse 1 7. Understanding Metaclasses. S.Ducasse 2 Roadmap Metaclasses in 7 points Indexed Classes Class Instance Variables Class Variables Pool Dictionaries.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
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.
Basic Object-Oriented concepts. Concept: Classes describe objects Every object belongs to (is an instance of) a class An object may have fields –The class.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
OOP Basics Classes & Methods (c) IDMS/SQL News
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Functional Programming Language: Haskell (cont’d) Lecture 20 – Functional Programming, Spring 2008.
Programming in Java: lecture 7
Topic: Classes and Objects
OOP: Encapsulation &Abstraction
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
Class 22: Inheritance CS150: Computer Science University of Virginia
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Programming Language Concepts (CIS 635)
Lecture 21: Inheritance CS200: Computer Science University of Virginia
Java Programming Language
Introduction to Smalltalk
Java Programming Language
Lecture 10 Concepts of Programming Languages
CSE 3302 Programming Languages
Presentation transcript:

Administrative Issues Lecture 22 – Prolog (III), Fall 2007 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, HW3 (due at March 18 th ) Essay (due at May 1 st ) – ABET requirement – 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 20th

CSE 3302 Programming Languages Chengkai Li Spring 2008 Smalltalk (cont.) Lecture 15 – OO Programming, Spring CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, 2008

About method arguments A>>f: x x := … Assignment to argument is not allowed. Why? Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, 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 different 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 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Object(Instance), Class, Inheritance Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, SmallInteger class SmallInteger 3 Metaclass Metaclass class Integer Number Magnitude Object ProtoObject Integer class inheritance instance of Number class

Examples “print it” and “inspect it” 3 3 class 3 class class 3 class class class 3 class class class class 3 class class class class class SmallInteger superclass Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Be wary of the confusing names in the following several slides!!! Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Instance 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 Example: Number subclass: #Fraction instanceVariableNames: 'numerator denominator' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Numbers' Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Instance 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 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Class 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 browser – Inherited in subclass (cannot be redefined in subclass) – The class and each subclass have their own copy Example: Very few in the system itself Float class instanceVariableNames: '‘ (empty) Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Class Instance Variables (Example) Examples:? Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Class 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>>one Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Class 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: #Float instanceVariableNames: '' 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 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Access 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) 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 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

For Accessing Private Data: Setter and Getter Example: class Complex instance variable real, imaginary getter Complex>>real ^real setter Complex>>real: aNumber real _ aNumber (remember _ means :=) Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Class Methods for Constructing New Instances Example: class Complex class methods: – Complex class>>real: aNumber1 imaginary: aNumber2 | newComplex | newComplex _ super new. newComplex real: aNumber1; imaginary: aNumber2. ^ newComplex – Complex class>>new ^ self real: 0 imaginary: 0 Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Class Methods for Accessing Class Variables Example: class Float class variable: Pi E Epsilon … class method: – Float class>>pi ^Pi Compare: – method real is defined in Complex, so an instance of Complex (e.g., 3+2i) can receive message real – method pi is defined in Float class (instead of Float ), so an instance of Float class (i.e., Float ) can receive message pi Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Inheritance and Handling Messages Inheritance: – Smalltalk allows only single inheritance Method Lookup along the inheritance chains When an object receives a message: – If the class of the object has the method, use it; – Otherwise check the superclass, and the superclass of the superclass, and so on. Return value of a method – Message receiver if no explicit return (i.e., no ^ ) Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Inheritance and Handling Messages Overriding – Multiple classes on inheritance chain may define the same method – Only the lowest one (starting from the receiver object) is used – Need to say “ super methodName ” if want to extend the method defined in some superclass (and this is a good practice) E.g., initialize, new, … self and super – both self and super refer to the message receiver itself ! – “self methodName” will start method looking-up from the class of the message receiver. – “super methodName” will start method looking-up from the parent class of the class that defines the method which sends this message “super methodName”. Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Example A>>m2 …. A subclass: #B … B>>m2 super m2 B subclass: #C… C>>m1 self m2 aC := C new. aC m1 What will happen if the lookup of m2 starts from the superclass of message receiver? Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,

Examples of Super and Self Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li, A B C D test Transcript show: ‘a’ result1 self test test Transcript show: ‘b’ result2 self result1 result3 super test test Transcript show: ‘d’ a := A new. b := B new. c := C new. d := D new.

Abstract Method, Abstract Class self subclassResponsibility Example: Number>>+… Different types of numbers (Integer, Float, Complex, … decide the implementation of + for themselves) Lecture 15 – OO Programming, Spring 2008 CSE3302 Programming Languages, UT-Arlington ©Chengkai Li,