programminglanguages programming languages comparison of object- oriented programming languages this...

22
Programming Programming Languages Languages

Upload: shauna-hodge

Post on 28-Dec-2015

235 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

ProgrammingProgramming LanguagesLanguages

Page 2: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Comparison of Object-Comparison of Object-OrientedOrientedProgramming Programming LanguagesLanguages

This lesson compares the object-oriented This lesson compares the object-oriented features of the following languages: features of the following languages:

Smalltalk, Java, C++, Python, Perl, Visual Smalltalk, Java, C++, Python, Perl, Visual Basic, etc.Basic, etc.

Page 3: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

• There are several qualities that an Object-There are several qualities that an Object-

Oriented language should have: Oriented language should have:

• 1.Encapsulation/Information Hiding 1.Encapsulation/Information Hiding

Object-OrientationObject-Orientation

• 2.Inheritance 2.Inheritance

• 3. Polymorphism/Dynamic Binding 3. Polymorphism/Dynamic Binding

• 4. All pre-defined types are Objects 4. All pre-defined types are Objects

• 5. All operations performed by sending 5. All operations performed by sending messages to Objects messages to Objects

• 6. All user-defined types are Objects 6. All user-defined types are Objects

Page 4: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

A Comparison Table:A Comparison Table:

Page 5: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

• C++ is considered to be a multi-paradigm C++ is considered to be a multi-paradigm language, of which one paradigm it supports language, of which one paradigm it supports is Object-Orientation. is Object-Orientation.

Pure and Hybrid (1)Pure and Hybrid (1)

• Java claims to be a pure Object-Oriented Java claims to be a pure Object-Oriented language, but its "basic“ types are not language, but its "basic“ types are not objects, and has basic arithmetic as built-in objects, and has basic arithmetic as built-in operators, rather than messages to objects. operators, rather than messages to objects.

• Eiffel, Smalltalk, and Ruby are all pure Object-Eiffel, Smalltalk, and Ruby are all pure Object-Oriented languages, supporting all six qualitiesOriented languages, supporting all six qualities

Page 6: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

• Python's lack of "private" or "hidden" Python's lack of "private" or "hidden" attributes, which goes against the attributes, which goes against the Encapsulation/Information Hiding principle.Encapsulation/Information Hiding principle.

Pure and Hybrid (2)Pure and Hybrid (2)• Python’s some operations are implemented as methods, Python’s some operations are implemented as methods,

while others are implemented as global functions. while others are implemented as global functions.

• Visual Basic and Perl are both procedural Visual Basic and Perl are both procedural languages that have had some Object-languages that have had some Object-Oriented support added on as the languages Oriented support added on as the languages have matured. have matured.

Page 7: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

• Static typing enforces safer, more reliable code, Static typing enforces safer, more reliable code, and increases efficiency of the resulting product. and increases efficiency of the resulting product.

Static vs. Dynamic Typing(1)Static vs. Dynamic Typing(1)

• Dynamic typing is more flexible and allows Dynamic typing is more flexible and allows for increased productivity. for increased productivity.

• Statically-typed language requires a very well-Statically-typed language requires a very well-defined type system in order to remain as defined type system in order to remain as flexible as its dynamically-typed counterparts. flexible as its dynamically-typed counterparts.

• A dynamic type system doesn't require A dynamic type system doesn't require variables to be declared as a specific type. variables to be declared as a specific type.

Page 8: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Static vs. Dynamic Typing (2)Static vs. Dynamic Typing (2)• Statically-typed languages require that all Statically-typed languages require that all

variables are declared with a specific type. variables are declared with a specific type.

• The compiler will then ensure that at any The compiler will then ensure that at any given time the variable contains only an given time the variable contains only an object compatible with that type. object compatible with that type.

• C++ also offers generic classes, as well as C++ also offers generic classes, as well as multiple inheritance.multiple inheritance.

• Unfortunately, the presence of type casts and Unfortunately, the presence of type casts and implicit type conversions can sometimes implicit type conversions can sometimes undermine the work of the compiler by allowing undermine the work of the compiler by allowing type errors to go undetected until run-time. type errors to go undetected until run-time.

Page 9: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Static vs. Dynamic Typing (3)Static vs. Dynamic Typing (3)

• Java is seriously hindered by a lack of Java is seriously hindered by a lack of generic classes.generic classes.

• Java also allows type casting, but some Java also allows type casting, but some rudimentary type checks can be made by the rudimentary type checks can be made by the compiler, making casts in Java somewhat safer compiler, making casts in Java somewhat safer than in C++ and other languages. than in C++ and other languages.

• But this scheme leaves much to be desired But this scheme leaves much to be desired in terms of type-safety.in terms of type-safety.

• This is alleviated to a degree by Java's singly-This is alleviated to a degree by Java's singly-rooted type hierarch.rooted type hierarch.

Page 10: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Generic Classes (1)Generic Classes (1)

• A common example is a stack class that is A common example is a stack class that is parameterized by the type of elements it contains.parameterized by the type of elements it contains.

• Generic classes, refer to the ability to Generic classes, refer to the ability to parameterize a class with specific data types. parameterize a class with specific data types.

• The primary benefit of parameterized types is The primary benefit of parameterized types is that it allows statically typed languages to retain that it allows statically typed languages to retain their compile-time type safety yet remain nearly their compile-time type safety yet remain nearly as flexible as dynamically typed languages.as flexible as dynamically typed languages.

• C++ templates are even more flexible, C++ templates are even more flexible, having many uses apart from simple generic having many uses apart from simple generic containers, but also much more complex. containers, but also much more complex.

Page 11: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Generic Classes (2)Generic Classes (2)• Dynamically typed languages do not need parameterized Dynamically typed languages do not need parameterized

types in order to support generic programming. types in order to support generic programming.

• Types are checked at run-time and thus Types are checked at run-time and thus dynamically typed languages support dynamically typed languages support generic programming inherently. generic programming inherently.

• Java's lack of generic classes is a severe Java's lack of generic classes is a severe hole in the Java type system. hole in the Java type system.

Page 12: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Inheritance (1)Inheritance (1)• Inheritance is the ability for a class or object Inheritance is the ability for a class or object

to be defined as an extension or to be defined as an extension or specialization of another class or object. specialization of another class or object.

• Most object-oriented languages support Most object-oriented languages support class-based inheritance, while JavaScript class-based inheritance, while JavaScript support object-based inheritance. support object-based inheritance.

• Python, support both class- and object-Python, support both class- and object-based inheritance.based inheritance.

Page 13: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Inheritance (2)Inheritance (2)• Multiple inheritance appears to be an Multiple inheritance appears to be an

essential feature for cases when two or essential feature for cases when two or more distinct hierarchies must be merged more distinct hierarchies must be merged into one application domain. into one application domain.

• Multiple inheritance introduces some Multiple inheritance introduces some complications into a programming language complications into a programming language supporting it; such as name clashes and supporting it; such as name clashes and ambiguities in the object model.ambiguities in the object model.

• C++ provides multiple inheritance that makes C++ provides multiple inheritance that makes it complicated and less flexible; leading many it complicated and less flexible; leading many people to believe that multiple inheritance is people to believe that multiple inheritance is inherently ill-conceived and complex. inherently ill-conceived and complex.

Page 14: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Inheritance (3)Inheritance (3)• Java, while it does not support pure Java, while it does not support pure

implementation inheritance, provides two implementation inheritance, provides two separate inheritance mechanisms:separate inheritance mechanisms:

• The extends keyword is used for a combination of The extends keyword is used for a combination of implementation and subtype inheritance;implementation and subtype inheritance;

• while the implements keyword is used for while the implements keyword is used for pure subtype (interface) inheritance. pure subtype (interface) inheritance.

• Visual Basic has support for single Visual Basic has support for single inheritance in the VB .NET release. inheritance in the VB .NET release.

Page 15: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Feature RenamingFeature Renaming• Feature renaming is the ability for a class or Feature renaming is the ability for a class or

object to rename one of its features that it object to rename one of its features that it inherited from a super class.inherited from a super class.

• This provide a feature with a more natural This provide a feature with a more natural name for its new context; name for its new context;

• And resolve naming ambiguities when a name is And resolve naming ambiguities when a name is inherited from multiple inheritance paths. inherited from multiple inheritance paths.

Page 16: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Method OverloadingMethod Overloading• Method overloading is the ability for a class, Method overloading is the ability for a class,

module, or other scope to have two or more module, or other scope to have two or more methods with the same name.methods with the same name.

• Calls to these methods are disambiguated by the Calls to these methods are disambiguated by the number and/or type of arguments passed to the method number and/or type of arguments passed to the method at the call site.at the call site.

• Java and C++ both support method Java and C++ both support method overloading in a similar fashion. overloading in a similar fashion.

Page 17: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Operator OverloadingOperator Overloading• Operator overloading is the ability for a Operator overloading is the ability for a

programmer to define an operator (such as programmer to define an operator (such as +, or *) for user-defined types. +, or *) for user-defined types.

• This allows the operator to be used in infix, This allows the operator to be used in infix, prefix, or postfix form, rather than the prefix, or postfix form, rather than the standard functional form.standard functional form.

• C++, and Python support operator overloading. C++, and Python support operator overloading.

Page 18: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Class variables and methodsClass variables and methods• Class variables and methods are owned by a class, Class variables and methods are owned by a class,

and not any particular instance of a class.and not any particular instance of a class.

• This means that for however many instances of This means that for however many instances of a class exist at any given point in time, only a class exist at any given point in time, only one copy of each class variable/method exists one copy of each class variable/method exists and is shared by every instance of the class. and is shared by every instance of the class.

• Java and C++ provide "static" members Java and C++ provide "static" members which are effectively the same thing, yet which are effectively the same thing, yet more limited since they cannot be inherited. more limited since they cannot be inherited.

Page 19: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

ReflectionReflection• Reflection is the ability for a program to determine Reflection is the ability for a program to determine

various pieces of information about an object at run-various pieces of information about an object at run-time. time.

• This includes the ability to determine the type This includes the ability to determine the type of the object, its inheritance structure, and the of the object, its inheritance structure, and the methods it contains, including the number and methods it contains, including the number and types of parameters and return types.types of parameters and return types.

• It might also include the ability for determining It might also include the ability for determining the names and types of attributes of the object. the names and types of attributes of the object.

• Most object-oriented languages support Most object-oriented languages support some form of reflection. some form of reflection.

Page 20: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Access ControlAccess Control• Access control refers to the ability for a modules Access control refers to the ability for a modules

implementation to remain hidden behind its public implementation to remain hidden behind its public interface. interface.

• Access control is closely related to the Access control is closely related to the encapsulation/information hiding principle of encapsulation/information hiding principle of object-oriented languages.object-oriented languages.

• Most object-oriented languages provide at Most object-oriented languages provide at least two levels of access control: public and least two levels of access control: public and protected.protected.

• Java and C++, provide a third level of Java and C++, provide a third level of access control known as "private". access control known as "private".

Page 21: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Pointer ArithmeticPointer Arithmetic• Pointer arithmetic is the ability for a language Pointer arithmetic is the ability for a language

to directly manipulate memory addresses and to directly manipulate memory addresses and their contents. their contents.

• While, due to the inherent unsafety of direct While, due to the inherent unsafety of direct memory manipulation, this ability is not often memory manipulation, this ability is not often considered appropriate for high-level considered appropriate for high-level languages, languages,

• C++ on the other hand provides direct C++ on the other hand provides direct support for pointer arithmetic, both for support for pointer arithmetic, both for compatibility with C and to allow C++ to be compatibility with C and to allow C++ to be used for systems programming without the used for systems programming without the need to drop down to a lower level language.need to drop down to a lower level language.

Page 22: ProgrammingLanguages Programming Languages Comparison of Object- Oriented Programming Languages This lesson compares the object-oriented features of

Built-In SecurityBuilt-In Security• Built-in security refers to a language Built-in security refers to a language

implementation's ability to determine whether or implementation's ability to determine whether or not a piece of code comes from a "trusted" source,not a piece of code comes from a "trusted" source,

• limiting the permissions of the code if it does not. limiting the permissions of the code if it does not.

• For example, Java applets are considered For example, Java applets are considered untrusted, and thus they are limited in the untrusted, and thus they are limited in the actions they can perform when executed actions they can perform when executed from a user's browser.from a user's browser.

• They may not read or write from or to the user's They may not read or write from or to the user's hard disk, and they may not open a network hard disk, and they may not open a network connection to anywhere but the originating host. connection to anywhere but the originating host.