1 / 143

An Introduction to Smalltalk First Pure Object Oriented Language By: Misagh Bagherian

An Introduction to Smalltalk First Pure Object Oriented Language By: Misagh Bagherian S.Jalal Kazemitabar Emad Livani University of Tehran – ECE Department Programming Languages Course, Fall 2004. Smalltalk Quotes. Common languages are tools, Smalltalk is a piece of art. Alan Kay:

shana
Download Presentation

An Introduction to Smalltalk First Pure Object Oriented Language By: Misagh Bagherian

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to Smalltalk First Pure Object Oriented Language By: Misagh Bagherian S.Jalal Kazemitabar Emad Livani University of Tehran – ECE Department Programming Languages Course, Fall 2004

  2. Smalltalk Quotes • Common languages are tools, Smalltalk is a piece of art. • Alan Kay: • Simple things should be simple. Complex things should be possible

  3. Outline • Motivation to Object-Oriented Programming • Smalltalk History • Structural Organization • Classes and Subclasses • Objects and Message Sending • Implementation: Classes and Objects • Syntax Overview • Conclusions

  4. Part 1 • Structured Programming • Object Orientation • Objects • ADTs • Encapsulation • Language Concepts • Smalltalk History • Why Smalltalk ?

  5. Structured Programming • Definetasks to be performed • Breaktasks into smaller and smaller pieces • Until you reach a size you can implement • Define the data structures to be manipulated • Design how functions interact • What's the input • What's the output • Group functions into components • "units" or “modules“ • Write the code

  6. Program Structure • Program Structure in Structural Approach Main Program Sub-program Sub-program Sub-program Sub-program Sub-program

  7. Abstract Data Types (ADTs) • Main ideas: • Separate interface from implementation • Example: • Sets have empty, insert, union, is_member?, … • Sets implemented as … linked list … • Use type checking to enforce separation • Client program only has access to operations in interface • Implementation encapsulated inside ADT construct

  8. Object Oriented Programming • First goal: Model the objects of the world • Noun-oriented • (in contrast to verb-orientation in Structured Programming) • Focus on the domain of the program • Phases • Object-oriented analysis: Understand the domain • Define an object-based model of it • Object-oriented design: Define an implementation strategy • Design the solution • Object-oriented programming: Build it

  9. Object Oriented Programming • Primary object-oriented language concepts • dynamic lookup • encapsulation • inheritance • sub typing

  10. hidden data msg1 method1 . . . . . . msgn methodn Objects • An object consists of • hidden data instance variables, also called member data hidden functions also possible • public operations methods or member functions can also have public variables in some languages • Object-oriented program: • Send messages to objects

  11. Object Orientation • Programming methodology • organize concepts into objects and classes • build extensible systems • Language concepts • dynamic lookup • encapsulation • subtyping allows extensions of concepts • inheritance allows reuse of implementation

  12. Dynamic Lookup • In object-oriented programming, object  message (arguments) code depends on object and message • In conventional programming, operation (operands) meaning of operation is always the same Fundamental difference between abstract data types and objects

  13. Example • Add two numbers x  add (y) different add if x is integer, complex, etc. • Conventional programming add (x, y) function add has fixed meaning • Very important distinction: • Overloading is resolved at compile time, • Dynamic lookup at run time

  14. Language concepts • “dynamic lookup” • different code for different object • integer “+” different from real “+” • encapsulation • sub typing • inheritance

  15. How’d we get from there to here? • How did we move from structured to object-oriented? • Key ideas • Master-drawings in Sketchpad • Simulation “objects” in Simula • Alan Kay and his desire to make software better • More robust • More maintainable • More scalable

  16. Encapsulation • Builder of a concept has detailed view • User of a concept has “abstract” view • Encapsulation separates these two views • Implementation code: operate on representation • Client code: operate by applying fixed set of operations provided by implementer of abstraction Object message

  17. Encapsulation • How does it support our objectives? • Models real world • examples: driving a car • Reusability & Ease of use • other users need only know ‘interface’, not the implementation

  18. Comparison with ADTs • Traditional (non-OO) approach to encapsulation is through abstract data types • Advantage • Separate interface from implementation • Disadvantage • Not extensible in the way that OOP is

  19. Abstract Data Types (ADTs) • Guarantee invariants of data structure • only functions of the data type have access to the internal representation of data • Limited “reuse” • Cannot apply queue code to pqueue, except by explicit parameterization, even though signatures identical • Cannot form list of points, colored points • Data abstraction is important part of OOP, innovation is that it occurs in an extensible form

  20. Alan Kay • University of Utah PhD student in 1966 • Read Sketchpad, Ported Simula • Saw “objects” as the future of computer science • His dissertation: Flex, an object-oriented personal computer • A personal computer was a radical idea then • How radical? "There is no reason anyone would want a computer in their home." (Ken Olsen, Digital Equipment Corp, 1977)

  21. Alan Kay • Alan C. Kay: ”In the 1990’s there will be millions of personal computers. They will be the size of notebooks of today, have high-resolution flat-screen reflective displays, weigh less than ten pounds, have ten to twenty times the computing and storage capacity of an Alto. Let’s call them Dynabooks. The purchase price will be about that of a color television set of the era, ...” (1971)

  22. Alan Kay • Alan Kay’s categorization of Programming Languages: • Agglutination of Features • Cobol, PL/1, Ada, etc. • Crystallization of Style • Lisp, APL, and Smalltalk

  23. Alan Kay’s Insights • “Computer” as collection of Networked Computers • All software is simulating the real world • Biology as model for objects • Bacterium has 120M of info, 1/500th of a Cell, and we have 10^13 of these in us • What man-made things can scale like that? • Stick a million dog houses together to get a skyscraper? • Internet does, but how can we make that the norm?

  24. Birth of Objects → Sketchpad • Ivan Sutherland's Sketchpad, 1963

  25. Birth of Objects → Sketchpad • First object-oriented drawing program • Master and instance drawings • Draw a house • Make two instances • Add a chimney to the master • Poof! The instances grow a chimney

  26. Birth of Objects → Simula • Simulation programming language from Norway, 1966 (Kristen Nygaard & Ole-Johan Dahl) • Define an activity which can be instantiated as processes • Each process has its own data and behavior • In real world, objects don't mess with each others' internals directly • (Simulated) Multi-processing • No Universal Scheduler in the Real World

  27. Birth of Objects • Objects as models of real world entities • Objects as Cells • Independent, indivisible, interacting -- in standard ways • Scales well • Complexity: Distributed responsibility, emergent complexity • Robustness: Independent • Supporting growth: Same mechanism everywhere • Reuse: Provide services, just like in real world

  28. A Personal Computer for Children • Flex, an object-oriented personal computer

  29. FLEX • Enabled by Moore's Law • Imagining personal computing in 1969 • Logo, Sketchpad, and Simula • Learning representations and knowledge through programming them • Keyboard and drawing tablet • Computer as meta-medium • The first medium to encompass other media

  30. Xerox PARC (Palo Alto Research Center) • Smalltalk-72 • Alan Kay, • Dan Ingalls, • Adele Goldberg, • Ted Kaehler

  31. Goal: Dynabook • Dynabook: • Small • Handheld • Wireless Networking • A Personal Computer for Children of All Ages Look familiar?

  32. Smalltalk Inventions • Interface: • overlapping Windows • Icons, even iconic programming • Pop-up menus • Mouse as Pointing device • Object-oriented programming • Multimedia authoring environment: Drawing, music, animations

  33. How Smalltalk was Implemented • Byte code compiler • Machine language for a make-believe computer • Virtual machine to create the make-believe computer • Invented years earlier by Burroughs • Used in UCSD Pascal, Java, Python, etc. • Four files needed for this implementation: • VM • Image file (in byte code) • Sources file (all sources always came along) • Changes file (added sources by user)

  34. Tradeoffs of Virtual Machines • Advantages: • Can be easily ported • If VM is well-designed, small amount of code needs to be written for each platform • The VM can be very small • PowerMac 308K, Win32 328K, Linux-Intel 276K, SGI Irix 609K, Solaris 816K • Disadvantages: • Hard to make it efficient

  35. 1981: Xerox releases Smalltalk-80 • In 1981: Finally Xerox releases Smalltalk-80

  36. Why Smalltalk ? • Pure object-oriented language • Uniform • Simple • Powerful • Dynamically typed (no type coercion…) • No primitive types • Syntax simple so force to think !!!!! • Discuss design, OO modeling and not syntax!!

  37. Why Smalltalk ? • Object Culture • Environment completely written in Smalltalk • Powerful development tools • Good to model real world applications

  38. Structural Organization Classes and Subclasses Objects and Message Sending Part 2

  39. Smalltalk:Interactive & Interpreted • To satisfy Dynabook’s requirements, it has to be highly interactive.  communication with either pointing or typing commands. • Primary ways of defining things: • Bind a name to an object X3 yx+1 • Class definition x*2 => send message ‘*2’ to object x

  40. Objects React to Messages • Smalltalk’s graphical orientation is taken from LOGO. • LOGO introduced a style of graphics: “turtle graphics”. Turtle  drawing object . In Smalltalk :pen.

  41. The position of a pen called Scribe Changing position and draw line Scribe goto: 200@400

  42. Draw another line: Scribe penup. Scribe goto:500@100. Scribe pendn. Scribe goto:500@400. Go to a specific direction: Scribe go:300

  43. Turn and draw: Scribe turn:90. Scribe go:300. Scribe turn:90. Scribe go:300. • Control Structures: • Scribe penup;goto:400@800; • pendn;turn 180. • 4 timesRepeat: • [Scribe go:100. Scribe turn:90]

  44. Important Ideas 1-Objects have a behavior. 2-Objects can be made to do things by sending them messages. 3-Repetitive operations can be simplified by using control structures.

  45. Instantiation • A class is just a name for a particular kind of object. • Every object is an instance of some class. • We have to indicate the class of the instance. • The process of creating an object is called instantiation.

  46. Instantiation is also a message sent to some object. • Which object should be sent the message ? • A universal system object responsible for all instantiations • The class relating the object. • For the sake of Information Hiding Principle: Each class is responsible for its own instantiation. • anotherScribe pen newAt: 200@800

  47. Class Definition • To draw another box - Move the pen - Instantiate a new pen • Violates the Abstraction Principle • A better solution: define a class box which can be instantiated any number of times

  48. In defining a class, there exists some instance methods and some class methods which describe the behavior of that class. (ex. Instantiation method newAt) • The instance variable “self”, is implicitly bound to the instance to which it is local.

  49. Example : box class • Class definition written in tabular form class name box loc tilt size scribe instance var names instance messages and methods shape || scribe penup; goto: loc; turnTo: tilt; pendn. 4 timesRepeat: [scribe go: size; turn: 90] erase || scribe color background. self shape

  50. Classes & Subclasses • Smalltalk objects model real-world objects • Many of the ideas in Smalltalk derive from Simula. • Data values inside an object can represent the properties and relations in which that object participates • The behavior of the Smalltalk object can model the behavior of the corresponding object

More Related