Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Concepts In Object Oriented Programming Languages


Published on

An overview lecture on OOP - presented at Department of Computer Science and Technology, BESU in 2004

Concepts In Object Oriented Programming Languages

  1. 1. Concepts in Object Oriented Programming Languages Dr. P P Das [email_address] Interra Systems India Pvt. Ltd. June 07, 2004
  2. 2. Outline of lecture <ul><li>Object-oriented Design & Primary Language Concepts </li></ul><ul><ul><li>dynamic lookup </li></ul></ul><ul><ul><li>encapsulation </li></ul></ul><ul><ul><li>inheritance </li></ul></ul><ul><ul><li>sub-typing </li></ul></ul><ul><li>Programming Languages – Past, Present & Future </li></ul><ul><ul><li>Understanding the Evolution Process </li></ul></ul><ul><li>Component Object Model </li></ul><ul><ul><li>Object Programming in a Language Independent Fashion </li></ul></ul>
  3. 3. Object-oriented Design & Primary Language Concepts <ul><ul><li>dynamic lookup </li></ul></ul><ul><ul><li>encapsulation </li></ul></ul><ul><ul><li>inheritance </li></ul></ul><ul><ul><li>sub-typing </li></ul></ul>
  4. 4. Objects <ul><li>An object consists of </li></ul><ul><ul><li>hidden data </li></ul></ul><ul><ul><ul><li>instance variables, also called member data </li></ul></ul></ul><ul><ul><ul><li>hidden functions also possible </li></ul></ul></ul><ul><ul><li>public operations </li></ul></ul><ul><ul><ul><li>methods or member functions </li></ul></ul></ul><ul><ul><ul><li>can also have public variables in some languages </li></ul></ul></ul><ul><li>Object-oriented program: </li></ul><ul><ul><li>Send messages to objects </li></ul></ul>
  5. 5. What’s interesting about this? <ul><li>Universal encapsulation construct </li></ul><ul><ul><li>Data structure </li></ul></ul><ul><ul><li>File system </li></ul></ul><ul><ul><li>Database </li></ul></ul><ul><ul><li>Window </li></ul></ul><ul><ul><li>Integer </li></ul></ul><ul><li>Metaphor usefully ambiguous </li></ul><ul><ul><li>sequential or concurrent computation </li></ul></ul><ul><ul><li>distributed, synchronous or asynchronous communication </li></ul></ul>
  6. 6. Object-Oriented Programming <ul><li>Programming methodology </li></ul><ul><ul><li>organize concepts into objects and classes </li></ul></ul><ul><ul><li>build extensible systems </li></ul></ul><ul><li>Language concepts </li></ul><ul><ul><li>encapsulate data and functions into objects </li></ul></ul><ul><ul><li>Sub-typing allows extensions of data types </li></ul></ul><ul><ul><li>inheritance allows reuse of implementation </li></ul></ul>
  7. 7. Object-Oriented Method <ul><li>Four steps </li></ul><ul><ul><li>Identify the objects at a given level of abstraction </li></ul></ul><ul><ul><li>Identify the semantics (intended behavior) of objects </li></ul></ul><ul><ul><li>Identify the relationships among the objects </li></ul></ul><ul><ul><li>Implement these objects </li></ul></ul><ul><li>Iterative process </li></ul><ul><ul><li>Implement objects by repeating these steps </li></ul></ul><ul><li>Not necessarily top-down </li></ul><ul><ul><li>“ Level of abstraction” could start anywhere </li></ul></ul>Booch
  8. 8. This Method <ul><li>Based on associating objects with components or concepts in a system </li></ul><ul><li>Why iterative? </li></ul><ul><ul><li>An object is typically implemented using a number of constituent objects </li></ul></ul><ul><ul><li>Apply same methodology to subsystems, underlying concepts </li></ul></ul>
  9. 9. Example: Compute Weight of Car <ul><li>Car object: </li></ul><ul><ul><li>Contains list of main parts (each an object) </li></ul></ul><ul><ul><ul><li>chassis, body, engine, drive train, wheel assemblies </li></ul></ul></ul><ul><ul><li>Method to compute weight </li></ul></ul><ul><ul><ul><li>sum the weights to compute total </li></ul></ul></ul><ul><li>Part objects: </li></ul><ul><ul><li>Each may have list of main sub-parts </li></ul></ul><ul><ul><li>Each must have method to compute weight </li></ul></ul><ul><li>Example: Compute Weight of Car </li></ul>
  10. 10. Example: Evaluation of a Filter
  11. 11. Comparison to top-down design <ul><li>Similarity: </li></ul><ul><ul><li>A task is typically accomplished by completing a number of finer-grained sub-tasks </li></ul></ul><ul><li>Differences: </li></ul><ul><ul><li>Focus of top-down design is on program structure </li></ul></ul><ul><ul><li>OO methods are based on modeling ideas </li></ul></ul><ul><ul><li>Combining functions and data into objects makes data refinement more natural </li></ul></ul>
  12. 12. Object-Orientation <ul><li>Programming methodology </li></ul><ul><ul><li>organize concepts into objects and classes </li></ul></ul><ul><ul><li>build extensible systems </li></ul></ul><ul><li>Language concepts </li></ul><ul><ul><li>dynamic lookup </li></ul></ul><ul><ul><li>encapsulation </li></ul></ul><ul><ul><li>sub-typing allows extensions of concepts </li></ul></ul><ul><ul><li>inheritance allows reuse of implementation </li></ul></ul>
  13. 13. Language concepts <ul><li>“ dynamic lookup” </li></ul><ul><ul><li>different code for different object </li></ul></ul><ul><ul><li>integer “+” different from real “+” </li></ul></ul><ul><li>encapsulation </li></ul><ul><li>sub-typing </li></ul><ul><li>inheritance </li></ul>
  14. 14. Dynamic Lookup <ul><li>In object-oriented programming, </li></ul><ul><ul><li>object  message (arguments) </li></ul></ul><ul><ul><li>code depends on object and message </li></ul></ul><ul><li>In conventional programming, </li></ul><ul><ul><li>operation (operands) </li></ul></ul><ul><ul><li>meaning of operation is always the same </li></ul></ul>
  15. 15. Example <ul><li>Add two numbers </li></ul><ul><ul><ul><li>x  add(y) </li></ul></ul></ul><ul><ul><li>different add if x is integer, complex </li></ul></ul><ul><li>Conventional programming add(x, y) </li></ul><ul><ul><li>function add has fixed meaning </li></ul></ul><ul><li>Very important distinction: </li></ul><ul><ul><li>Overloading is resolved at compile time, </li></ul></ul><ul><ul><li>Dynamic lookup at run time </li></ul></ul>
  16. 16. Language concepts <ul><li>“dynamic lookup” </li></ul><ul><ul><li>different code for different object </li></ul></ul><ul><ul><li>integer “+” different from real “+” </li></ul></ul><ul><li>encapsulation </li></ul><ul><li>sub-typing </li></ul><ul><li>inheritance </li></ul>
  17. 17. Encapsulation <ul><li>Builder of a concept has detailed view </li></ul><ul><li>User of a concept has “abstract” view </li></ul><ul><li>Encapsulation is the mechanism for separating these two views </li></ul>
  18. 18. Comparison <ul><li>Traditional approach to encapsulation is through abstract data types </li></ul><ul><li>Advantage </li></ul><ul><ul><li>Separate interface from implementation </li></ul></ul><ul><li>Disadvantage </li></ul><ul><ul><li>Not extensible in the way that OOP is </li></ul></ul>
  19. 19. Abstract Data Types <ul><li>abstype q </li></ul><ul><ul><li>with </li></ul></ul><ul><ul><ul><li>mk_Queue : unit -> q </li></ul></ul></ul><ul><ul><ul><li>is_empty : q -> bool </li></ul></ul></ul><ul><ul><ul><li>insert : q * elem -> q </li></ul></ul></ul><ul><ul><ul><li>remove : q -> elem </li></ul></ul></ul><ul><ul><li>is … </li></ul></ul><ul><ul><li>in </li></ul></ul><ul><ul><ul><li>program </li></ul></ul></ul><ul><ul><li>end </li></ul></ul>
  20. 20. Priority Q, similar to Queue <ul><li>abstype pq </li></ul><ul><ul><li>with </li></ul></ul><ul><ul><ul><li>mk_Queue : unit -> pq </li></ul></ul></ul><ul><ul><ul><li>is_empty : pq -> bool </li></ul></ul></ul><ul><ul><ul><li>insert : pq * elem -> pq </li></ul></ul></ul><ul><ul><ul><li>remove : pq -> elem </li></ul></ul></ul><ul><ul><li>is … </li></ul></ul><ul><ul><li>in </li></ul></ul><ul><ul><ul><li>program </li></ul></ul></ul><ul><ul><li>end </li></ul></ul><ul><li>But cannot intermix pq’s and q’s </li></ul>
  21. 21. Abstract Data Types <ul><li>Guarantee invariants of data structure </li></ul><ul><ul><li>only functions of the data type have access to the internal representation of data </li></ul></ul><ul><li>Limited “reuse” </li></ul><ul><ul><li>Cannot apply queue code to pqueue, except by explicit parameterization, even though signatures identical </li></ul></ul><ul><ul><li>Cannot form list of points, colored points </li></ul></ul><ul><li>Data abstraction is important part of OOP, innovation is that it occurs in an extensible form </li></ul>
  22. 22. Language concepts <ul><li>“dynamic lookup” </li></ul><ul><ul><li>different code for different object </li></ul></ul><ul><ul><li>integer “+” different from real “+” </li></ul></ul><ul><li>encapsulation </li></ul><ul><li>sub-typing </li></ul><ul><li>inheritance </li></ul>
  23. 23. Sub-typing and Inheritance <ul><li>Interface </li></ul><ul><ul><li>The external view of an object </li></ul></ul><ul><li>Sub-typing </li></ul><ul><ul><li>Relation between interfaces </li></ul></ul><ul><li>Implementation </li></ul><ul><ul><li>The internal representation of an object </li></ul></ul><ul><li>Inheritance </li></ul><ul><ul><li>Relation between implementations </li></ul></ul>
  24. 24. Object Interfaces <ul><li>Interface </li></ul><ul><ul><li>The messages understood by an object </li></ul></ul><ul><li>Example: point </li></ul><ul><ul><li>x-coord : returns x-coordinate of a point </li></ul></ul><ul><ul><li>y -coord : returns y -coordinate of a point </li></ul></ul><ul><ul><li>move : method for changing location </li></ul></ul><ul><li>The interface of an object is its type. </li></ul>
  25. 25. Sub-typing <ul><li>If interface A contains all of interface B, then A objects can also be used B objects. </li></ul><ul><li>Colored_point interface contains Point </li></ul><ul><ul><li>Colored_point is a subtype of Point </li></ul></ul>change_color color move move y -coord y -coord x-coord x-coord Colored_point Point
  26. 26. Inheritance <ul><li>Implementation mechanism </li></ul><ul><li>New objects may be defined by reusing implementations of other objects </li></ul>
  27. 27. Example <ul><li>class Point </li></ul><ul><ul><li>private </li></ul></ul><ul><ul><ul><li>float x, y </li></ul></ul></ul><ul><ul><li>public </li></ul></ul><ul><ul><ul><li>point move (float dx, float dy); </li></ul></ul></ul><ul><li>class Colored_point </li></ul><ul><ul><li>private </li></ul></ul><ul><ul><ul><li>float x, y; color c </li></ul></ul></ul><ul><ul><li>public </li></ul></ul><ul><ul><ul><li>point move(float dx, float dy); </li></ul></ul></ul><ul><ul><ul><li>point change_color(color newc); </li></ul></ul></ul><ul><li>Sub-typing </li></ul><ul><ul><li>Colored points can be used in place of points </li></ul></ul><ul><ul><li>Property used by client program </li></ul></ul><ul><li>Inheritance </li></ul><ul><ul><li>Colored points can be implemented by reusing point implementation </li></ul></ul><ul><ul><li>Property used by implementer of classes </li></ul></ul>
  28. 28. OO Program Structure <ul><li>Group data and functions </li></ul><ul><li>Class </li></ul><ul><ul><li>Defines behavior of all objects that are instances of the class </li></ul></ul><ul><li>Sub-typing </li></ul><ul><ul><li>Place similar data in related classes </li></ul></ul><ul><li>Inheritance </li></ul><ul><ul><li>Avoid re-implementing functions that are already defined </li></ul></ul>
  29. 29. Example: Geometry Library <ul><li>Define general concept shape </li></ul><ul><li>Implement two shapes: circle, rectangle </li></ul><ul><li>Functions on implemented shapes </li></ul><ul><ul><ul><li>center, move, rotate, print </li></ul></ul></ul><ul><li>Anticipate additions to library </li></ul>
  30. 30. Shapes <ul><li>Interface of every shape must include </li></ul><ul><ul><ul><li>center, move, rotate, print </li></ul></ul></ul><ul><li>Different kinds of shapes are implemented differently </li></ul><ul><ul><li>Square: four points, representing corners </li></ul></ul><ul><ul><li>Circle: center point and radius </li></ul></ul>
  31. 31. Subtype hierarchy <ul><li>Shape </li></ul><ul><li>Circle Rectangle </li></ul><ul><li>General interface defined in the shape class </li></ul><ul><li>Implementations defined in circle, rectangle </li></ul><ul><li>Extend hierarchy with additional shapes </li></ul>
  32. 32. Code placed in classes <ul><li>Dynamic lookup </li></ul><ul><ul><li>circle  move(x,y) calls function c_move </li></ul></ul><ul><li>Conventional organization </li></ul><ul><ul><li>Place c_move, r_move in move function </li></ul></ul>r_center r_move r_rotate r_print Rectangle c_center c_move c_rotate c_print Circle center move rotate print
  33. 33. Example use: Processing Loop <ul><li>Loop </li></ul><ul><li>{ </li></ul><ul><ul><li>Remove shape from work queue </li></ul></ul><ul><ul><li>Perform action </li></ul></ul><ul><li>} </li></ul><ul><li>Control loop does not know the type of each shape </li></ul>
  34. 34. Sub-typing differs from inheritance <ul><li>Collection </li></ul><ul><li>Indexed Set </li></ul><ul><li>Array Dictionary Sorted Set </li></ul><ul><li>String </li></ul><ul><li>Sub-typing </li></ul><ul><li>Inheritance </li></ul>
  35. 35. Design Patterns <ul><li>Classes and objects are useful organizing concepts </li></ul><ul><li>Culture of design patterns has developed around object-oriented programming </li></ul><ul><ul><li>Shows value of OOP for program organization and problem solving </li></ul></ul>
  36. 36. What is a design pattern? <ul><li>General solution that has developed from repeatedly addressing similar problems. </li></ul><ul><li>Example: singleton </li></ul><ul><ul><li>Restrict programs so that only one instance of a class can be created </li></ul></ul><ul><ul><li>Singleton design pattern provides standard solution </li></ul></ul><ul><li>Not a class template </li></ul><ul><ul><li>Using most patterns will require some thought </li></ul></ul><ul><ul><li>Pattern is meant to capture experience in useful form </li></ul></ul><ul><li>Standard reference: Gamma, Helm, Johnson, Vlissides </li></ul>
  37. 37. OOP in Conventional Language <ul><li>Records provide “dynamic lookup” </li></ul><ul><li>Scoping provides another form of encapsulation </li></ul><ul><ul><li>Try object-oriented programming in ML. Will it work? </li></ul></ul><ul><ul><li>Let’s see what’s fundamental to OOP </li></ul></ul>
  38. 38. Dynamic Lookup (again) <ul><ul><ul><li>receiver  operation (arguments) </li></ul></ul></ul><ul><li>code depends on receiver and operation </li></ul><ul><li>This is may be achieved in conventional languages using record with function components </li></ul>
  39. 39. Stacks as closures <ul><li>fun create_stack(x) = </li></ul><ul><ul><li>let val store = ref [x] in </li></ul></ul><ul><ul><ul><li>{push = fn (y) => </li></ul></ul></ul><ul><ul><ul><ul><li>store := y::(!store), </li></ul></ul></ul></ul><ul><ul><ul><li>pop = fn () => </li></ul></ul></ul><ul><ul><ul><ul><li>case !store of </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>nil => raise Empty | </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>y::m => (store := m; y) </li></ul></ul></ul></ul></ul><ul><ul><ul><li>} end; </li></ul></ul></ul><ul><li>val stk = create_stack(1); </li></ul><ul><ul><li>stk = {pop=fn,push=fn} : {pop:unit -> int, push:int -> unit} </li></ul></ul>
  40. 40. Does this work ??? <ul><li>Depends on what you mean by “work” </li></ul><ul><li>Provides </li></ul><ul><ul><li>encapsulation of private data </li></ul></ul><ul><ul><li>dynamic lookup </li></ul></ul><ul><li>But </li></ul><ul><ul><li>cannot substitute extended stacks for stacks </li></ul></ul><ul><ul><li>only weak form of inheritance </li></ul></ul><ul><ul><ul><li>can add new operations to stack </li></ul></ul></ul><ul><ul><ul><li>not mutually recursive with old operations </li></ul></ul></ul>
  41. 41. Programming Languages – Past, Present & Future Understanding the Evolution Process
  42. 42. Connection between Functional & OO <ul><li>λ -Calculus </li></ul><ul><li>Functional Programming </li></ul><ul><ul><li>Impractical </li></ul></ul><ul><ul><li>Strong Mathematical Properties </li></ul></ul><ul><li>Turing Machine </li></ul><ul><li>Procedural </li></ul><ul><ul><li>Practical </li></ul></ul><ul><ul><li>Little Math Grounding </li></ul></ul><ul><li>Object-Oriented </li></ul><ul><ul><li>Very Practical (fixes problems) </li></ul></ul><ul><ul><li>No Math Basis/ Chaos Theory </li></ul></ul>Future of OO – What we want to see
  43. 43. Fortran (1957-66) <ul><li>Program Structure </li></ul><ul><ul><li>Flat </li></ul></ul><ul><ul><ul><li>No recursion </li></ul></ul></ul><ul><ul><ul><li>No nested scopes </li></ul></ul></ul><ul><ul><ul><ul><li>No statement grouping </li></ul></ul></ul></ul><ul><ul><ul><li>No control structures </li></ul></ul></ul><ul><ul><ul><ul><li>goto & computed goto </li></ul></ul></ul></ul><ul><ul><ul><ul><li>if (like computed goto) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>do (based around labels) </li></ul></ul></ul></ul><ul><ul><li>Static </li></ul></ul><ul><li>Data Structure </li></ul><ul><ul><li>Flat </li></ul></ul><ul><ul><ul><li>Arrays </li></ul></ul></ul><ul><ul><ul><li>Later strings </li></ul></ul></ul><ul><ul><ul><li>Only locals & globals </li></ul></ul></ul><ul><ul><li>Static </li></ul></ul><ul><ul><ul><li>No dynamic allocation </li></ul></ul></ul><ul><ul><ul><li>All locations picked at compile time </li></ul></ul></ul>
  44. 44. Fortran: Abstractions? <ul><li>Functions/Procedures </li></ul><ul><li>Absolutely no layered abstraction </li></ul><ul><ul><li>Layered Abstraction: “first understand in general or in the abstract what’s going on; then worry about the details.” Apply recursively for best effect </li></ul></ul><ul><li>At Least it’s consistent </li></ul><ul><li>Achieved its goal to replace assembly </li></ul><ul><li>Got people to actually use programming languages </li></ul>
  45. 45. Algol 60 <ul><li>Program Structure </li></ul><ul><ul><li>Recursive </li></ul></ul><ul><ul><ul><li>Nested scopes </li></ul></ul></ul><ul><ul><ul><li>Modules </li></ul></ul></ul><ul><ul><ul><li>Recursive function calls </li></ul></ul></ul><ul><ul><ul><li>Full set of control structures </li></ul></ul></ul><ul><ul><li>Static </li></ul></ul><ul><li>Data Structure </li></ul><ul><ul><li>Flat </li></ul></ul><ul><ul><ul><li>Arrays </li></ul></ul></ul><ul><ul><ul><li>No records </li></ul></ul></ul><ul><ul><li>Dynamic </li></ul></ul><ul><ul><ul><li>Dynamically sized arrays </li></ul></ul></ul>“ Algol Wall ” Data and program structure are separate worlds
  46. 46. Algol 60 <ul><li>Discovered Recursive Program Structure. </li></ul>
  47. 47. Lisp (60-65) <ul><li>Program Structure </li></ul><ul><ul><li>Recursive </li></ul></ul><ul><ul><ul><li>Structure </li></ul></ul></ul><ul><ul><ul><li>Calls </li></ul></ul></ul><ul><ul><li>Static </li></ul></ul><ul><ul><ul><li>Functions still aren’t first class values </li></ul></ul></ul><ul><ul><li>Dynamic Binding </li></ul></ul><ul><ul><ul><li>variables are bound within the calling environment </li></ul></ul></ul><ul><li>Data Structure </li></ul><ul><ul><li>Recursive </li></ul></ul><ul><ul><ul><li>Atoms </li></ul></ul></ul><ul><ul><ul><li>Lists </li></ul></ul></ul><ul><ul><li>Heterogeneous Lists </li></ul></ul><ul><ul><li>Dynamic </li></ul></ul><ul><ul><ul><li>Garbage collection </li></ul></ul></ul><ul><ul><li>No records </li></ul></ul>
  48. 48. PL/I (1964) and Algol 68 <ul><li>PL/I for example: </li></ul><ul><ul><li>DECLARE FOOBAR DECIMAL FIXED REAL (8,3) STATIC EXTERNAL </li></ul></ul><ul><li>Algol 68: </li></ul><ul><ul><li>Allows anything, for example: </li></ul></ul><ul><ul><ul><li>this is an acceptable name for a variable of type integer </li></ul></ul></ul><ul><ul><li>Operator overloading, unions, pointers to anything, Call-by-reference </li></ul></ul><ul><ul><li>Everything is first class and transparent, including procedures </li></ul></ul><ul><ul><li>Yet: procedures are objects while structs “extend the language”, structures are based on arrays and one has data and programs and never shall the twain meet </li></ul></ul>
  49. 49. Pascal (1971-74) <ul><li>Program Structure </li></ul><ul><ul><li>Partially recursive </li></ul></ul><ul><ul><ul><li>Procedures with recursive calls </li></ul></ul></ul><ul><ul><ul><li>No true blocks, only compound statements </li></ul></ul></ul><ul><ul><li>Static </li></ul></ul><ul><li>Data Structure </li></ul><ul><ul><li>Flat </li></ul></ul><ul><ul><li>Records </li></ul></ul><ul><ul><ul><li>Dynamic </li></ul></ul></ul><ul><ul><ul><li>Record types extend type system </li></ul></ul></ul><ul><ul><ul><li>Based on arrays </li></ul></ul></ul><ul><ul><li>Strongly typed </li></ul></ul>Most importantly its simple! Temporarily reversed the trend
  50. 50. Simula 67 <ul><li>The first Object-Oriented Language! </li></ul><ul><li>The “Algol Wall” falls at last! </li></ul><ul><li>Well, almost </li></ul>
  51. 51. Simula 67: the language <ul><li>Program Structure </li></ul><ul><ul><li>Recursive </li></ul></ul><ul><ul><li>Same as others </li></ul></ul><ul><li>Data Structure </li></ul><ul><ul><li>Recursive </li></ul></ul><ul><ul><li>Dynamic </li></ul></ul><ul><ul><li>Classes & Objects </li></ul></ul><ul><ul><ul><li>Classes instantiate objects </li></ul></ul></ul><ul><ul><ul><li>Classes have code and take parameters </li></ul></ul></ul><ul><ul><ul><li>Inheritance </li></ul></ul></ul>
  52. 52. Smalltalk (1972-76) <ul><li>No primitives </li></ul><ul><li>Classes are objects </li></ul><ul><li>Even blocks are objects </li></ul><ul><li>Dynamically typed </li></ul><ul><li>Extremely uniform </li></ul><ul><li>Despite all this, it never was quite “it” </li></ul><ul><li>Syntax is nearly unreadable, example: </li></ul><ul><ul><li>Given a “Point” class the plus method might be: </li></ul></ul><ul><ul><ul><li>+pt [ Point new x: x+pt x y: y+pt y] </li></ul></ul></ul>
  53. 53. Ada (mid 1970s) <ul><li>A complicated language designed for the DOD </li></ul><ul><li>Based on Pascal </li></ul><ul><li>Many different forms of packaging and data type declarations </li></ul><ul><li>Strong typing with the flexibility of making new types </li></ul><ul><li>Security was important (unlike Smalltalk and Scheme) </li></ul><ul><li>No quite Object-Oriented </li></ul>
  54. 54. C, C++ and Eiffel <ul><li>C gave us </li></ul><ul><ul><li>{ } for blocks and lots of other nice syntax </li></ul></ul><ul><li>C++ made </li></ul><ul><ul><li>OO and exceptions mainstream </li></ul></ul><ul><ul><li>Const allows expression of invariance </li></ul></ul><ul><li>Eiffel is in the Pascal family </li></ul><ul><ul><li>It is a well thought out OO language </li></ul></ul><ul><ul><li>Gave us the concept of whole program optimization </li></ul></ul><ul><ul><li>Hopefully the last of the Pascal line </li></ul></ul>
  55. 55. Java <ul><li>Anonymous Inner Classes </li></ul><ul><li>Have pretty good generics semantics </li></ul><ul><li>Simplifies C++ greatly </li></ul>The Hero Language?
  56. 56. Prototype Based OO Languages Self etc. <ul><li>No classes, only objects </li></ul><ul><li>New objects are made by cloning others </li></ul><ul><li>A “class” is just an object you use as a template </li></ul><ul><li>Can directly write objects and often add methods/properties on the fly </li></ul><ul><li>May be strongly or weakly typed </li></ul>
  57. 57. BETA <ul><li>Everything is a “pattern” </li></ul><ul><li>Patterns make up classes and methods </li></ul><ul><li>There is no direct representation of an object </li></ul><ul><li>Very similar to functional languages like Scheme </li></ul><ul><li>Strongly typed </li></ul>
  58. 58. The Future? <ul><li>Patterns are first class entities representing classes and methods </li></ul><ul><li>Direct object representations allow inner objects and modules </li></ul><ul><li>Ways to express invariance </li></ul><ul><li>Anonymous patterns and objects </li></ul><ul><li>Integration of Generics into the polymorphism system </li></ul>
  59. 59. Component Object Model Object Programming in a Language Independent Fashion
  60. 60. The Component Object Model <ul><li>COM is: </li></ul><ul><ul><li>Platform-independent, </li></ul></ul><ul><ul><li>Distributed, </li></ul></ul><ul><ul><li>Object-oriented, </li></ul></ul><ul><ul><li>System for creating binary software components that can interact. </li></ul></ul><ul><li>Foundation technology for: </li></ul><ul><ul><li>Microsoft's OLE (compound documents), </li></ul></ul><ul><ul><li>ActiveX (internet enabled components), </li></ul></ul><ul><ul><li>Automation </li></ul></ul><ul><ul><li>Others. </li></ul></ul>
  61. 61. What COM is NOT? <ul><li>It is NOT an object-oriented language, </li></ul><ul><li>It is NOT a coding or s/w Architecture Standard. </li></ul><ul><li>It DOES NOT bind the Language, structure, and implementation details. </li></ul><ul><li>It is NOT Language-specific </li></ul>
  62. 62. What COM is? <ul><li>It is a Binary standard applicable after a program has been translated to binary machine code </li></ul><ul><li>It is an object model and programming requirements that enable COM objects to interact with other objects. </li></ul><ul><li>COM objects can be within a single process, in other processes, even on remote machines. </li></ul><ul><li>COM objects may be written in different languages, and may be structurally quite dissimilar. </li></ul>
  63. 63. Language Requirement for COM <ul><li>The language that can create </li></ul><ul><ul><li>Structures of pointers and, </li></ul></ul><ul><ul><li>Call functions through pointers (either explicitly or implicitly) </li></ul></ul><ul><li>Object-oriented languages simplify the implementation of COM objects </li></ul><ul><ul><li>C++, Smalltalk and Java </li></ul></ul><ul><li>But other languages can be used: </li></ul><ul><ul><li>C, Pascal, Ada, and even BASIC programming environments can create and use COM objects. </li></ul></ul>
  64. 64. Nature of a COM <ul><li>A software object is made up of : </li></ul><ul><ul><li>A set of data and </li></ul></ul><ul><ul><li>The functions that manipulate the data. </li></ul></ul><ul><li>In a COM object the access to the object’s data is achieved exclusively through one or more sets of related functions. </li></ul><ul><ul><li>These function sets are called interfaces , and </li></ul></ul><ul><ul><li>The functions of an interface are called methods. </li></ul></ul><ul><li>The only way to gain access to the methods of an interface is through a pointer to the interface. </li></ul>
  65. 65. Universal Interfaces <ul><li>COM defines: </li></ul><ul><ul><li>Basic interfaces that provide functions common to all COM-based technologies, </li></ul></ul><ul><ul><li>A small number of API functions that all components require, </li></ul></ul><ul><ul><li>How objects work together over a distributed environment, and </li></ul></ul><ul><ul><li>Security features to ensure system and component integrity. </li></ul></ul>
  66. 66. COM Objects and Interfaces <ul><li>Allows objects to interact across process and machine boundaries (as objects within a single process interact. </li></ul><ul><li>The only way to manipulate the data associated with an object is through “an interface on the object”. </li></ul><ul><li>“ An object that implements an interface” means that the object uses code that implements each method of the interface and provides COM binary-compliant pointers to those functions to the COM library. </li></ul><ul><li>COM makes those functions available to any client who asks for a pointer to the interface, whether the client is inside or outside of the process that implements those functions. </li></ul>
  67. 67. Interfaces & Interface Implementations <ul><li>COM makes a fundamental distinction between: </li></ul><ul><ul><li>Interface Definitions and </li></ul></ul><ul><ul><li>Interface Implementations. </li></ul></ul><ul><li>An interface is actually a contract that consists of a group of related function prototypes whose usage is defined but whose implementation is not. </li></ul><ul><li>An interface implementation is the code a programmer supplies to carry out the actions specified in an interface definition. </li></ul>
  68. 68. Interfaces <ul><li>An interface is a contract consisting of a group of related function prototypes whose usage is defined but whose implementation is not. </li></ul><ul><ul><li>The function prototypes are equivalent to pure virtual base classes in C++ programming. </li></ul></ul><ul><ul><li>An interface definition specifies the interface’s member functions, called methods, their return types, the number and types of their parameters, and what they must do. </li></ul></ul><ul><ul><li>There is no implementation associated with an interface. </li></ul></ul>
  69. 69. Interface Implementations <ul><li>An interface implementation is the code a programmer supplies to carry out the actions specified in an interface definition. </li></ul><ul><ul><li>Implementations of many of the interfaces a programmer could use in an object-based application are included in the COM libraries. </li></ul></ul><ul><ul><li>Programmers are free to ignore these implementations and write their own. </li></ul></ul><ul><ul><li>An interface implementation is to be associated with an object when an instance of that object is created, and provides the services that the object offers. </li></ul></ul>
  70. 70. IStack <ul><li>A hypothetical interface named IStack </li></ul><ul><li>Two methods – Push and Pop , </li></ul><ul><li>successive calls to the Pop method return, in reverse order, values previously passed to the Push method. </li></ul><ul><li>This interface definition, however, would not specify how the functions are to be implemented in code. </li></ul><ul><li>In implementing the interface, however, one programmer might implement the stack as an array and implement the Push and Pop methods in such a way as to access that array; while another programmer might prefer to use a linked list and would implement the methods accordingly. </li></ul><ul><li>Regardless of a particular implementation of the Push and Pop methods, however, the in-memory representation of a pointer to an IStack interface, and therefore its use by a client, is completely defined by the interface definition. </li></ul>
  71. 71. “ Interface” Connotations <ul><li>A C++ interface refers to all of the functions that a class supports and that clients of an object can call to interact with it. </li></ul><ul><li>A COM interface refers to a predefined group of related functions that a COM class implements, but does not necessarily represent all the functions that the class supports. </li></ul><ul><li>Java defines “interfaces” in just the same way as COM. </li></ul>
  72. 72. Universally Unique Identifier (GUID) <ul><ul><li>A 128-bit value that uniquely identifies objects: </li></ul></ul><ul><ul><li>OLE servers </li></ul></ul><ul><ul><li>Interfaces </li></ul></ul><ul><ul><li>Manager entry-point vectors, and </li></ul></ul><ul><ul><li>Client objects </li></ul></ul><ul><ul><li>Universally unique identifiers are used in cross-process communication, such as remote procedure calling (RPC) and OLE. </li></ul></ul><ul><ul><li>Also called Globally Unique Identifier (GUID). </li></ul></ul>
  73. 73. How an Interface Works? <ul><li>An instantiation of an interface implementation (the defined interfaces themselves cannot be instantiated without implementation) is simply pointer to an array of pointers to functions. </li></ul><ul><li>Any code that has access to that array – a pointer through which it can access the array – can call the functions in that interface. </li></ul><ul><li>A pointer to an interface is actually a pointer to a pointer to the table of function pointers. The term interface pointer is used to refer to this multiple indirection. </li></ul>
  74. 74. How an Interface Works? <ul><li>Conceptually, then, an interface pointer can be viewed simply as a pointer to a function table in which you can call those functions by de-referencing them by means of the interface pointer. </li></ul>
  75. 75. IUnknown & Interface Inheritance <ul><li>Inheritance in COM does not mean code reuse. </li></ul><ul><li>W/o any implementations with interfaces, interface inheritance !  code inheritance. </li></ul><ul><li>By inheritance, the contract associated with an interface is inherited in a C++ pure-virtual base-class fashion and modified </li></ul><ul><ul><li>by adding new methods or </li></ul></ul><ul><ul><li>by further qualifying the allowed usage of methods. </li></ul></ul><ul><li>There is no selective inheritance in COM. If one interface inherits from another, it includes all the methods that the other interface defines. </li></ul>
  76. 76. Interface Inheritance <ul><li>Inheritance is rare (but found) in predefined COM interfaces. </li></ul><ul><li>All interfaces (predefined / custom) must inherit their definitions from IUnknown containing: </li></ul><ul><ul><li>QueryInterface – allows to move freely between the different interfaces that an object supports </li></ul></ul><ul><ul><li>AddRef – to manage object lifetime (Birth) </li></ul></ul><ul><ul><li>Release – to manage object lifetime (Death) </li></ul></ul><ul><li>All COM objects must implement the IUnknown interface. </li></ul>
  77. 77. Examples
  78. 78. Summary <ul><li>Object-Orientation is a matter of discipline </li></ul><ul><ul><li>Language just works as a vehicle </li></ul></ul><ul><li>OO works at every level of abstraction </li></ul><ul><ul><li>Design </li></ul></ul><ul><ul><li>Source </li></ul></ul><ul><ul><li>Binary </li></ul></ul>