Presentation is loading. Please wait.

Presentation is loading. Please wait.

Comparison of OO Programming Languages © Jason Voegele, 2003.

Similar presentations


Presentation on theme: "Comparison of OO Programming Languages © Jason Voegele, 2003."— Presentation transcript:

1 Comparison of OO Programming Languages © Jason Voegele, 2003

2 C-S 5462 Characteristics of an OO Programming Language Encapsulation / Information Hiding Inheritance Polymorphism / Dynamic Binding All pre-defined types are objects All operations performed by sending messages to objects All user-defined types are objects

3 C-S 5463 OO Languages - Comparison PropertiesEiffelSmallta lk RubyJavaC#C++Visual Basic 1Yes Yes? 2Yes No 3Yes Yes? 4Yes No 5Yes No 6Yes No

4 C-S 5464 Observations Eiffel, Smalltalk and Ruby are the pure OO languages Java and C# fail to meet properties 4 and 5; many OO designers still accept that it is not a serious issue. C++ does not satisfy properties 4, 5 and 6. Lack of property 6 leads to inconsistencies in the set of objects created in the program. VB is simply a procedural language with some OO features – should not be considered to implement an OO design

5 C-S 5465 Static Vs Dynamic Binding Static binding –Every variable has a fixed, permanent type attached to the variable at compile time Dynamic binding –A variable has no fixed type; its type changes dynamically as the program executes Hybrid binding –A variable has a fixed type assigned at compile time, but it may assume other types during run-time through polymorphic substitutions

6 C-S 5466 Static and Dynamic Binding (continued) Smalltalk and Ruby are the only languages that support dynamic binding Eiffel, Java, C# and C++ support hybrid binding Visual Basic supports only static binding When a language uses generic classes (templates), it supports hybrid binding –Eiffel, C# and C++ Future version of Java is expected to support generic classes

7 C-S 5467 Inheritance Almost all OO languages, except VB, support inheritance Multiple inheritance is supported by Eiffel and C++ –Jason Voegele argues that Eiffel’s mechanisms to handle conflicts in multiple inheritance is neat and clear than those in C++ Java does not support multiple inheritance directly, but can be realized through interfaces

8 C-S 5468 Class based inheritance Vs Object based inheritance Most OO languages support class base inheritance –A class designated as the subclass of a superclass –Objects of subclasses can be substituted for objects of superclass (polymorphism) –Subtype inheritance Some languages support object based inheritance –Objects can inherit features from other objects during run-time SELF and Javascript support this feature Ruby supports both class based and object based inheritance

9 C-S 5469 Method overloading and operator overloading Method overloading –Same name for more than one method –Differentiated by the number and/or type of parameters –Supported by Java and C++ only Operator overloading –Overloading the meaning of one or more of the language symbols such as “+” and “*” –Supported by Eiffel, Ruby, C++

10 C-S 54610 Operator overloading - expectations All operations in the system must be messages to objects –Executions with operators are considered to be equivalent to message calls Operators must have equivalent functional forms –1 + 2 is the same as 1. + (2) Smalltalk, Ruby and Eiffel support both of these features C++ supports neither, even though it supports operator overloading

11 C-S 54611 Higher order functions Functions whose arguments are functions themselves –Example: calculate_tax (find year(), tax_rate) The scope of the functions that are passed as parameters must also be visible or computable Smalltalk and Ruby support higher order functions; recent version of Eiffel supports too. Java, C# and C++ do not support this feature; neither does VB. Another function

12 C-S 54612 Garbage Collection Mechanism to free memory of unused objects Mark and sweep method –One phase marks the unused objects and another phase cleans them up –Both phases are done at unspecified time (programmer does not know) –Smalltalk, Eiffel, Ruby and Java support this mechanism Reference count mechanism –Used by Visual Basic; has its own problems C++ does not support garbage collection

13 C-S 54613 Class variables Variables that are declared as static in a class and are accessible to all instances of that class –Only one copy of each class variable exists and is shared by all instances Smalltalk, Ruby, Java, C# and C++ support this feature though the implementation mechanisms are slightly different Smalltalk also supports additional classifications such as “pool variables” that are shared by only a group of classes –An extended mechanism of class variables

14 C-S 54614 Access Control Access to various features of a class are generally declared as “public” or “private” in most OO languages Java, C# and C++ support “protected” by which private features of a class can be accessed by its subclasses –In these languages, a private feature can be accessed by any member of the same object or objects of the same class as well –C++ supports “friend” mechanism by which another class B can access the private features of a class A as long as B is declared as a friend of A  this violates the encapsulation property Eiffel supports selective export, much similar to “protected” In Smalltalk, methods can be “public” or “private” but attributes are strictly “private” only.

15 C-S 54615 Design by Contract A notion introduced by Bertrand Meyer Each method is designed with a contract described by “pre” and “post-conditions”, and “invariants” Eiffel is the only language that supports this feature Java and Ruby has libraries that tend to support the design by contract feature, but it is not at the same level as in Eiffel

16 C-S 54616 Concurrency Concurrency is generally supported in OO languages by threads of execution control Almost all languages support multi-threading It is explicit in Java, C# and C++ but somewhat indirect(?) in Smalltalk VB supports it through timers Ruby supports threading not only in its syntax but a separate built-in interpreter, and hence does not rely on OS support for its implementation.

17 C-S 54617 Pointer Arithmetic Allows a program to directly manipulate memory addressed through “pointers”. –Goal is to improve run-time efficiency C++ is the only language that supports pointers Other OO languages tend not to support pointer arithmetic because –Pointers are not OO concepts/principles –Misuse of (or improper use of) pointers will lead to a lot of programming problems that are not part of the application domain


Download ppt "Comparison of OO Programming Languages © Jason Voegele, 2003."

Similar presentations


Ads by Google