Published on

Published in: Education
1 Comment
1 Like
  • LUPEET, ahaha..
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  2. 2. INTRODUCTION Languages that support OOP are firmly entrenched in the mainstream. From COBOL to LISP c++, Ada 95, and CLOS, an OOP version of LISP. C++ and Ada 95 support procedural- and data-oriented programming, CLOS also supports funcitonal programming. Some of the newer languages that were designed to support object-oriented programming do not support other programming paradigms, but still employ some of the basic structures and have the appearance of the older imperative languages. Among these are Eiffel and Java. Smalltalk was the first language to offer complete support for object-oriented programming. This is inheritance, which is at the center of object-oriented programming and the languages that support it.
  3. 3. INTRODUCTION The concept of object-oriented programming has its roots in SIMULA 67 but was not fully developed until the evolution of Smalltalk resulted in producing Smalltalk 80 (in1980, of course). Three key languages: -abstract data types -inheritance -a particular kind of dynamic binding Procedure-oriented programming focuses on subprograms and subprogram libraries. Data-oriented programming focuses on abstract data types. The Sorting process is enacted by calling that operation on the specific array object. The data-oriented programming paradigm was popular in the 1980s, and it served by the data abstraction facilities of Modula-2, Ada, and several more recent languages. Object-based languages are the languages that support data-oriented programming. Object-Oriented Programming
  4. 4. INHERITANCE By the middle to late 1980s, it became apparent to many software developers that one of the best opportunities for increased productivity in their profession was in software reuse. Abstract data types, with their encapsulation and access controls, were obviously the units to be reused. The problem with the reuse of abstract data types is that, nearly all cases, the features and capabilities of the existing type are not quite right for the new use. Second problem is with data-oriented programming is that all abstract data type definitions are independent and are at the same level. This often makes it impossible to structure a program to fit the problem space being addressed by the program.
  5. 5. Inheritance offers a solution to both modification problem posed by abstract data type and the program organization problem. If a new abstract data type can inherit the data and functionality of some existing type, and is also allowed to modify some of those Entities and add new entities, reuse is greatly facilitated without changes to the reused data type. The abstract data types in OOP, following the lead of SIMULA 67, are usually called classes . As with instances of abstract data types, Class instances are called objects . A class that is defined through Inheritance from another class is a derived class or subclass . A class from which the new class is derived is its parent class or superclass . The sub-programs that define the operations on objects of a class are Called methods . The calls to methods are often called messages . The entire collection of methods of an objects is called the message protocol , or message interface , of the object.
  6. 6. A modified method has the same name. and often the same protocol, As the one of which it is a modification. The new method is said to override the inherited version, which is then called an overriden method. The most common purpose of an overriding method Is to provide an operation that is specific for objects of the derived class but is not appropriate for objects of the parent class. classes can have two kinds of methods and variables. The most commonly used methods and variables are called instance methods And variables. Every object of a class has its own set of instance variables, which store the objects state. The only difference between two objects of the same class is the state of their instance variables. Instance methods operate only on the objects of the class. Class variables belong to the class, rather than its object, so there only one copy for the class. Class methods can perform operations on the class, and possibly also on the objects of the class.
  7. 7. If a new class is a subclass of a single parent class, then the Derivation process is called single inheritance. If a class has more than one parent class, the process is called multiple inheritance. When a number of classes are related through single inheritance, their relationships to each other can be shown in a derivation tree. The class relationship in a multiple inheritance can be shown in a derivation graph. One disadvantage of inheritance as a means Of increasing the possibility of reuse is that it creates a dependency Among the classes in an inheritance hierarchy.
  8. 8. Polymorphism and Dynamic Binding 3 rd characteristics of OOP language is a kind of polymorphism provided by the dynamic binding of messages to method definitions. This is supported by allowing one to define polymorphic variables of the type of the parent class that are also able to reference objects of any of the subclass of that class. The parent class can define a method that is overridden by its subclass. Virtual method , any class that includes at least one virtual method is called a virtual class. Such as class cannot be instantiated because not all of its methods have bodies.
  9. 9. Computing with an OOP language All computing in pure OOP language is done by the same uniform technique: sending a message to an object to invoke one of its methods. A reply to a message is an object that returns the value of the computation of the method. An executing program in an object-oriented language can be described as a simulation of a collection of computers (objects) that communicate with each other through messages. In addition, objects can send and receive messages. In essence, those are the fundamental capabilities of computers: to store and manipulate data and to communicate. The essence of object-oriented programming is solving problems by identifying the real-world objects of the problem and the processing required of those objects, and then creating simulations of those objects, their processes, and the required communications between the objects.
  10. 10. Design Issues for Object-Oriented Languages The Exclusivity of Objects A language designer who is totally committed to the object model of computation designs an object system that absorbs all other concepts of type. The advantage of this choice is the elegant and pure uniformity of the language and its use. The primary disadvantage is that simple operations must be done through the message-passing process which often makes them slower than similar operations in an imperative model, where machine instructions implement such simple operations. One alternative to the exclusive use of objects that is common in imperative languages to which support for object-oriented programming has been added is to retain a complete imperative typing model and simply add the object model. This result in a larger languages whose type structure is confusing to all but expert users. Another alternative to the exclusive use of objects is to have an imperative-style type structure for the primitive scalar types. This provides the speed of operations on primitive values that is comparable to those expected in the imperative model. This alternative subclasses access to the “hidden” part of the parent class makes the subclass dependent on those details.
  11. 11. On the other hand, keeping the implementation part of the parent class hidden from the subclasses can cause inefficiencies in the execution of the instances of those subclasses. This can be caused by the difference in efficiency of having direct access to data structures versus requiring access through the operations defined in the parent class. However, if the language designer has chosen interface inheritance, this code would look something like int second ( ) { int temp = top ( ) ; pop ( ) ; int temp_result = top ( ) ; push (temp) ; return temp_result; } This is clearly a slower process than the direct access to the second element from the top of the stack. The best solution for the language designer is to provide both implementation and interface inheritance options to the software designer and let him or her decide, on a case-by-case basis, which version is better.
  12. 12. Type Checking and Polymorphism Polymorphism in the object-oriented realm is defined to be the use of a polymorphic pointer or reference to access a method whose name is overridden in the class hierarchy that defines the object to which the pointer or reference is defined to point. The Polymorphic Variable is the type of class, and the parent class defines at least the protocol of a method that is overridden by the derived classes. It can reference objects of the parent class and the derived classes, so the class of the object to which it points cannot always be statically determined. The issue here is when the type checking of this binding takes place. This issue is an important one, for it aligns with the fundamental nature of the programming language. The use of Multiple Inheritance can easily lead to complex program organizations. Maintenance of system that use multiple inheritance can be a more serious problem, for multiple inheritance leads to more complex dependencies among classes. It is not clear to some that the benefits of multiple inheritance are worth the added effort to design and maintain a system using it.
  13. 13. Allocation and Deallocation of Objects There are two design questions concerning the allocation and deallocation of objects. The first of these is the place from which objects are allocated. If they behave like the abstract data types, then perhaps they can be allocated from anywhere. This means they could be statically allocated by the compiler, allocated as stack-dynamic objects from the run-time stack, or explicitly created on the heap with an operator or function such as new. The second question here is concerned with those cases where objects are alloctated from the heap. The question is whether deallocation is implicit or explicit or both. If deallocation is implicit, some implicit method of storage reclamation is required, such as reference counters or the garbage collection. If allocation can be explicit, that raises the issue of whether dangling pointers or reference can be created.
  14. 14. Dynamic and Static Binding The question here is whether all binding of messages to methods is dynamic. The alternative is to allow the user to specify whether a specific binding is to be dynamic or static. The advantage of this is that static bindings are faster. So if binding need not be dynamic, why pay price?
  15. 15. Support for OOP in java As with c++, java does not use objects exclusively. However, in java only values of the primitive scalar types ( Boolean, character and the numeric) are not objects. Java has no enumeration or record types, and its arrays are objects. The reason to have nonobjects is efficiency. However, having a two type systems leads to some cumbersome situations. One of these in java is that the predefined data structure Vector can only contain objects. So if you want to put a primitive type value into a Vector object, the value must first be placed in an object. This can be done by creating a new object of the wrapper class for the primitive type. Such class has an instance variable of that primitive type and a constructor that takes a value of the primitive type as a parameter and assigns it to its instance variable. Whereas c++ classes can be defined to have no parent, that is not possible in java. All java classes must be subclass of the root class, object, or some class is that there are some operations that are universally needed. All java objects are explicit heap dynamic. Most are allocated with the NEW operator.
  16. 16. Inheritance Java supports only single inheritance. However, it includes a kind of virtual class, called in interface, which provides aversion of multiple inheritance. An interface definition is similar to a class definition, except that it can contain named constants and method declaration. It defines only the specification of a class. The typical use of an interface is to define a class that inherits both some of the methods and variables from its parent class, and also implements a parent interface. Applets are programs that are interpreted by a World Wide Web browser after being downloaded from a Web server. These applets all need certain capabilities, which they can inherit from the predefined class, applet. This concurrency is supported by a predefined class named thread. But java includes a predefined interface named runnable that supplies the interface (but not the implementation) to one of the methods of Thread. The syntax of the header of such an applet is exemplified by : public class Clock extends Applet implements Runnable. In java, a method can be defined to be final, which means that it can not be overriden in any descendant class. When the final reserved word is specified on a class definition, it means the class cannot be the parent of any subclass.
  17. 17. Encapsulation 2 Kinds of encapsulation : Package- is a logical, rather than a physical, encapsulation: Any class definition can specify that it belongs in a particular package. Classes- a class that does not specify a package name is placed in an unnamed package. A Package creates a new name space. Any method or variable that does not include an access modifier (private, protected, or public) has what is called Package Scope. This is an expansion of the definition of protected as used in C++, in which protected members are visible only in the class where they are defined and in subclasses of that class. It is an alternative to the friends of C++, which are meant to provide access to private methods and instance variables in class to other specified methods or classes. In effect, all non-private variables and methods of all the classes in a package are friends.
  18. 18. Evaluation Java’s design for supporting object-oriented programming is similar to that of C++, but differs from it in several significant ways. In keeping with its consistent adherence to object-oriented principles, as in its lack of functions, Java does not allow parentless classes. It also uses dynamic binding as the “normal” approach to bind method calls to method definitions.