CSC/ECE 517 Fall 2010/ch1 1e vs: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 60: Line 60:


==Features of Object Oriented Programming:==
==Features of Object Oriented Programming:==
*'''[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance]:''' [http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance] defines relationships among classes in an object-oriented language.It helps objects work together and makes it easy to extend  existing structures to produce new structures with slightly different behavior. Example: In Java programming language, all classes descend from java.lang.Object and implement its methods.
*'''[http://en.wikipedia.org/wiki/Inheritance_(computer_science) Inheritance]:''' Inheritance defines relationships among [http://en.wikipedia.org/wiki/Class_(computer_science) classes] in an [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented language].It helps [http://en.wikipedia.org/wiki/Object_(computer_science) objects] work together and makes it easy to extend  existing structures to produce new structures with slightly different behavior. Example: In [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language, all classes descend from java.lang.Object and implement its methods.


*'''[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]:''' [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation] is defined as the process of binding or wrapping the data and the code that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Encapsulation acts as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.
*'''[http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]:''' Encapsulation is defined as the process of binding or wrapping the data and the code that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Encapsulation acts as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.


*'''Data Abstraction:''' Data abstration is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details. Abstraction can denote a model, a view, or some other focused representation for an actual item. It is the development of a software object to represent an object we can find in the real world. Abstraction is used to manage complexity.
*'''[http://en.wikipedia.org/wiki/Data_abstraction Data Abstraction]:''' Data abstration is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details. Abstraction can denote a model, a view, or some other focused representation for an actual item. It is the development of a software object to represent an object we can find in the real world. Abstraction is used to manage complexity.


*'''Polymorphism:''' Polymorphism enables one entity to be used as as general category for different types of actions.The concept of polymorphism can be explained as "one interface, multiple methods". Polymorphism results from the fact that every class lives in its own name space. The names assigned within a class definition will not conflict with names assigned anywhere outside it. This is true both of the instance variables in an object's data structure and of the object's methods. There are two basic types of polymorphism. Overridding, also called run-time polymorphism and Overloading, which is referred to as compile-time polymorphism.
*'''Polymorphism:''' Polymorphism enables one entity to be used as as general category for different types of actions.The concept of polymorphism can be explained as "one interface, multiple methods". Polymorphism results from the fact that every class lives in its own name space. The names assigned within a class definition will not conflict with names assigned anywhere outside it. This is true both of the instance variables in an object's data structure and of the object's methods. There are two basic types of polymorphism. Overridding, also called run-time polymorphism and Overloading, which is referred to as compile-time polymorphism.

Revision as of 15:25, 31 August 2011

CSC/ECE 517 Fall 2010/ch1 1e vs


Introduction

This article mainly compares and contrasts Block-Structured languages and Object-Oriented languages and also focuses on the advantages of Object-Oriented languages over Block-structured languages. It also emphasizes on the usage of block structures in Object-Oriented programming.

What is a Block-Structured Language?

A block is a section of code which is grouped together and consists of one or more declarations and statements.

A block structured programming languages is a class of high level programming languages that allows the creation of blocks and includes the nested blocks as components where nesting could be extended to any depth. Block structured languages have a syntax such that the structures are enclosed within the bracketed keywords like if....fi in ALGOL language.

An example of a block in ALGOL looks as shown below:

begin
  integer N;
  Read Int(N);
  begin
    real array Data[1:N]
    real sum,avg;
    sum:=0;
    for i:=1 step 1 until N do
       begin real val;
        Read Real (val);
        Data[i]:=if val<0 then -val else val
       end;
    for i:=1 step 1 until N do
     sum:=sum+Data[i];
   avg:=sum/N;
   Print Real(avg);
  end 
end

What is an Object-Oriented Programming?

Object-Oriented programming is a programming paradigm using "objects"- the data structures which consists of data fields and methods together with their interactions to design the applications and computer programs. The programming techniques include features like data abstraction, encapsulation, messaging, polymorphism and inheritance. It is a type of programming language where the programmers define not only the data type of a structure but also the type of functions that can be applied to the data structure.

An example of the code from JAVA language is as follows:

Class HelloWorld
{
  public static void main(String args[])
  {
    System.out.println("Hello world!"):
    System.out.println("Arguments you have entered is:");
    if (args.length>0)
    {
      for(int i=0;i<args.length;i++)
      {
        System.out.print(args[i]+" ");
      }
      System.out.println();
    }
   else
      System.out.println("<<No Arguments>>");
   } 
}

Features of Object Oriented Programming:

  • Inheritance: Inheritance defines relationships among classes in an object-oriented language.It helps objects work together and makes it easy to extend existing structures to produce new structures with slightly different behavior. Example: In Java programming language, all classes descend from java.lang.Object and implement its methods.
  • Encapsulation: Encapsulation is defined as the process of binding or wrapping the data and the code that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Encapsulation acts as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.
  • Data Abstraction: Data abstration is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details. Abstraction can denote a model, a view, or some other focused representation for an actual item. It is the development of a software object to represent an object we can find in the real world. Abstraction is used to manage complexity.
  • Polymorphism: Polymorphism enables one entity to be used as as general category for different types of actions.The concept of polymorphism can be explained as "one interface, multiple methods". Polymorphism results from the fact that every class lives in its own name space. The names assigned within a class definition will not conflict with names assigned anywhere outside it. This is true both of the instance variables in an object's data structure and of the object's methods. There are two basic types of polymorphism. Overridding, also called run-time polymorphism and Overloading, which is referred to as compile-time polymorphism.

Transition from Block Structured to Object Oriented Programming

The principle idea behind structured programming was the idea of divide and conquer. A computer program was considered as a set of tasks and any task that is too complex to be described simply would be broken down into a set of smaller component tasks, until the tasks were sufficiently small and self-contained enough that they were easily understood. Some examples of structured programming languages are: FORTRAN, Pascal, ALGOL etc.

Structured programming remained an enormously successful approach for dealing with complex problems until the late 1980s, when the size of programs increased and some of the deficiencies of structured programming had become evident.Some of these problems included:

  • Ensuring parameters are correctly passed to the correct subprogram.
  • Hierarchical structuring for data and procedures produced cumbersome code with large amounts of "tramp data"
  • Usage of global subprogram names and variables was recognized dangerous.
  • Also, a small change, such as requesting a user-chosen new option (text font-color) could cause a massive ripple-effect with changing multiple subprograms to propagate the new data into the program's hierarchy.

Object-oriented programming was developed to respond to these needs, providing techniques for managing enormous complexity, achieving reuse of software components, and coupling data with the tasks that manipulate that data.Object Oriented programming paradigm used "objects" which were considered to be data structures consisting of data fields and methods together with their interactions. It also took the concept of subroutines into a completely different zone. Programming techniques included features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance which changed the face of programming for many people.Some of the most commonly used object oriented programming languages are: C++, Java etc..