Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 331 Programming LanguagesDate: 4/21/08 Object Oriented Programming Group Featuring: James Webber II Topics Include: OOPSmalltalk.

Similar presentations


Presentation on theme: "CS 331 Programming LanguagesDate: 4/21/08 Object Oriented Programming Group Featuring: James Webber II Topics Include: OOPSmalltalk."— Presentation transcript:

1 CS 331 Programming LanguagesDate: 4/21/08 Object Oriented Programming Group Featuring: James Webber II Topics Include: OOPSmalltalk

2 CS 331 Programming LanguagesDate: 4/21/08 3 Key language features Abstract Data Types Abstract Data Types –Requires abstraction: I don’t want to know what’s in a car that makes it work, it just needs to work with the definitions given to me –Basically unique data type defined by programmer Inheritance Inheritance –Bestow, add, or modify characteristics of an existing class by creating a subclass with the same basic characteristics Dynamic call of method calls to methods Dynamic call of method calls to methods –Basically means accessing methods of a subclass by using a base class’ pointer (aka polymorphism)

3 CS 331 Programming LanguagesDate: 4/21/08 Smalltalk: The First OOPL Program consists entirely of objects & everything is treated uniformly Program consists entirely of objects & everything is treated uniformly Messages can be parameterized with variables that reference objects Messages can be parameterized with variables that reference objects ALL objects referenced from heap and all objects are implicitly dereferenced ALL objects referenced from heap and all objects are implicitly dereferenced –No explicit dereferencing: there is a garbage collection process Smalltalk is also a pure OOPL in that all data types are objects and all operations on them are methods Smalltalk is also a pure OOPL in that all data types are objects and all operations on them are methods

4 CS 331 Programming LanguagesDate: 4/21/08 Inheritance What is the point of inheritance? What is the point of inheritance? –Organize & Modify programs  Organize accessible data of subclasses  Modify existing data by redifining definitions of the superclass in a subclass Mammal -> primate -> human -> student -> CS student Throw in intelligence Increase intelligence (theoretically) beast Further increase intelligence at the cost of social skills and remove 30 minutes of life Remove sleep and finances

5 CS 331 Programming LanguagesDate: 4/21/08 Inheritance Terminology Object: Class Instances Object: Class Instances Method: subprograms which define operations on objects Method: subprograms which define operations on objects Message: call to a method Message: call to a method Message protocol: entire collection of methods Message protocol: entire collection of methods Overridden method: a base class method which is redefined in a derived class Overridden method: a base class method which is redefined in a derived class

6 CS 331 Programming LanguagesDate: 4/21/08 An Inheritance issue The Diamond Problem The Diamond Problem –Classes B and C both inherit from A –Class D inherits from both B and C –If method in D calls a method in A and both B and C have overriden the method, which method does D inherit? The Diamond Solution The Diamond Solution –Different languages solve this problem in different ways

7 CS 331 Programming LanguagesDate: 4/21/08 Access Control: What is inherited? Public: publicly accessible members inherited from the base class stay publicly accessible in derived class Public: publicly accessible members inherited from the base class stay publicly accessible in derived class Protected: members are not accessible from outside the class except in derived classes (they remain protected there) Protected: members are not accessible from outside the class except in derived classes (they remain protected there) Private: public and protected members of the base class are made private in the derived class Private: public and protected members of the base class are made private in the derived class C++ terminology

8 CS 331 Programming LanguagesDate: 4/21/08 Dynamic Binding Polymorphic reference / pointer: when a pointer to a base class’ object has the capability to point to a derived class’ object Polymorphic reference / pointer: when a pointer to a base class’ object has the capability to point to a derived class’ object –These are determined at run-time via the object’s type Abstract method: a protocol that is within the body of the base class (a hollow shell) which is defined in the derived class Abstract method: a protocol that is within the body of the base class (a hollow shell) which is defined in the derived class –A class that includes at least one abstract method is called an abstract class C++ terminology

9 CS 331 Programming LanguagesDate: 4/21/08 Alan Kay Designer of smalltalk Designer of smalltalk Wrote thesis on “dynabook” concept Wrote thesis on “dynabook” concept –Described laptops / tablet PCs (kind of)  Described small & portable computer  Described infinite battery life  Described purpose: teach children (target audience is not adults) Performed studies on children Performed studies on children –Children learn best kinetically with motion using images, symbols, abstract representation –Heavy influence on OLPC (one laptop per child) Employed by Xerox Parc at time Smalltalk Invented Employed by Xerox Parc at time Smalltalk Invented

10 CS 331 Programming LanguagesDate: 4/21/08 Development of Smalltalk Developed by Xerox Palo Alto Research Center employees Developed by Xerox Palo Alto Research Center employees –Most notable are Alan Kay(design) and Adele Goldberg (group leader/implementation management) When people reference smalltalk, they normally reference the 1980 version dubbed “smalltalk-80” When people reference smalltalk, they normally reference the 1980 version dubbed “smalltalk-80”

11 CS 331 Programming LanguagesDate: 4/21/08 Smalltalk Timeline: 1971- Kay creates smalltalk due to bet: “page of code” message passing programming language 1971- Kay creates smalltalk due to bet: “page of code” message passing programming language 1971-1972- an actually researched smalltalk-72 is created 1971-1972- an actually researched smalltalk-72 is created End of 1976- a development environment included (GUI) End of 1976- a development environment included (GUI) 1980- first language made available outside of Xerox PARC 1980- first language made available outside of Xerox PARC –Added metaclasses (class whose instance is a class) –Apple, HP, universities called for “peer review” –Made ANSI standard in 1998

12 CS 331 Programming LanguagesDate: 4/21/08 Smalltalk’s Diamond solution Recall that the diamond solution is different for every language Inheritance can be a real pain, keeping track of multiple inheritance can be worse if there are more overriden classes like B and C Smalltalk’s solution: let’s not deal with it… only single inheritance is allowed

13 CS 331 Programming LanguagesDate: 4/21/08 The Single Inheritance Life The life of a message: The life of a message: –Message to object causes class to be searched for corresponding method dynamically  Search fails… go to superclass  Repeat until system superclass OBJECT –Has no superclass –If not found… ERROR! The price of the message: The price of the message: –Due to this process being performed for everything dynamically (everything is an object) smalltalk programs are significantly slower than its comparable programs on different languages

14 CS 331 Programming LanguagesDate: 4/21/08 Classes and Inheritance A subclass inherits all instance variables, instance methods and class methods of its super class A subclass inherits all instance variables, instance methods and class methods of its super class –A subclass’ own instance variables must differ from those of superclass –if override method of superclass in a subclass then the superclass’ definition becomes hidden

15 CS 331 Programming LanguagesDate: 4/21/08 Smalltalk Typechecking The only method of typechecking is ensuring that a message matches some method The only method of typechecking is ensuring that a message matches some method Variables aren’t typed: names can be bound to any object Variables aren’t typed: names can be bound to any object –Variable types are irrelevant as long as they are consistent –Meaning of operation on variable determined by class of the object to which it is bound

16 CS 331 Programming LanguagesDate: 4/21/08 Methods, Messages, Blocks Method: class subprogram which defines operation on object Method: class subprogram which defines operation on object Message: most fundamental language construct Message: most fundamental language construct –42 factorial “sends factorial to object 42” –2 raisedTo: 4 “4 is argument to raisedTo and this is passed into 2” Block: a block of code expressed as a literal value Block: a block of code expressed as a literal value –An object that holds executable statements, what it does with the code is dependent on the context –[ :x | x+1 ] “the same as f(x)=x+1” –iftrue: [ ^somevalue]. –Iffalse:[^somevalue].

17 CS 331 Programming LanguagesDate: 4/21/08 Let’s Program w/ Squeak! http://www.squeak.org/ http://www.squeak.org/ http://www.squeak.org/ –Supports: Windows, Mac, Linux –Also Developed by Alan Kay Remember: everything is an object and Smalltalk has limited keywords! C++Smalltalk Int a = 5; a:=5 //comment“comment” ;. return a; ^a ClassName obj; ClassName new

18 CS 331 Programming LanguagesDate: 4/21/08 First Thing’s First

19 CS 331 Programming LanguagesDate: 4/21/08 The Confusion

20 CS 331 Programming LanguagesDate: 4/21/08 Basic Stuff to Know

21 CS 331 Programming LanguagesDate: 4/21/08 Class and Inheritance Example

22 CS 331 Programming LanguagesDate: 4/21/08 Current Status and the Future of Smalltalk Currently has a large following, very popular Currently has a large following, very popular Implemented in the OLPC as the primary OS Implemented in the OLPC as the primary OS Multinational language support; open source SQUEAK is available for those who want to try it Multinational language support; open source SQUEAK is available for those who want to try it

23 CS 331 Programming LanguagesDate: 4/21/08 Conclusion OOP OOP –ADTs –Inheritance –Dynamic Calls to Methods SmallTalk SmallTalk –First OOPL –pure OOPL –Contributed to modern GUI –Everything is an object  As a result, everything runs slowly –Order of Operations: left to right regardless (parenthesis support)

24 CS 331 Programming LanguagesDate: 4/21/08 References Sebesta: OOP, Smalltalk Basics Sebesta: OOP, Smalltalk Basics http://en.wikipedia.org/wiki/Diamond_problem http://en.wikipedia.org/wiki/Diamond_problem http://en.wikipedia.org/wiki/Diamond_problem http://en.wikipedia.org/wiki/Alan_Kay http://en.wikipedia.org/wiki/Alan_Kay http://en.wikipedia.org/wiki/Alan_Kay http://www.squeak.org/ http://www.squeak.org/ http://www.squeak.org/ http://gnu.paracoda.com/software/smalltalk/gst- manual/gst_34.html#SEC75 http://gnu.paracoda.com/software/smalltalk/gst- manual/gst_34.html#SEC75 http://www.outbacksoftware.com/smalltalk/smal ltalk.html http://www.outbacksoftware.com/smalltalk/smal ltalk.html James Webber II: Squeak Images & implementation James Webber II: Squeak Images & implementation


Download ppt "CS 331 Programming LanguagesDate: 4/21/08 Object Oriented Programming Group Featuring: James Webber II Topics Include: OOPSmalltalk."

Similar presentations


Ads by Google