Home > Java > Object-oriented Programming > Introduction
Introduction

Introduction to Object-oriented Programming

Object-oriented programming is a programming language model prepared around "objects" rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.


The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them.


Object-oriented programming has roots that can be traced to the 1960s. As hardware and software became increasingly complex, quality was often compromised. Researchers studied ways to maintain software quality and developed object-oriented programming in part to address common problems by strongly emphasizing discrete, reusable units of programming logic. The methodology focuses on data rather than processes, with programs composed of self-sufficient modules (objects) each containing all the information needed to manipulate its own data structure.


Programming techniques may include features such as information hiding, data abstraction, encapsulation, modularity, polymorphism, and inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support Object-oriented Programming.


Alan Kay summarized five basic characteristics of Smalltalk, the first successful object-oriented language and one of the languages upon which Java is based. These characteristics represent a pure approach to object-oriented programming:

 

  • Everything is an object. Think of an object as a fancy variable; it stores data, but you can “make requests” to that object, asking it to perform operations on itself. In theory, you can take any conceptual component in the problem you’re trying to solve (dogs, buildings, services, etc.) and represent it as an object in your program.
  • A program is a bunch of objects telling each other what to do by sending messages. To make a request of an object, you “send a message” to that object. More concretely, you can think of a message as a request to call a method that belongs to a particular object.
  • Each object has its own memory made up of other objects. Put another way, you create a new kind of object by making a package containing existing objects. Thus, you can build complexity into a program while hiding it behind the simplicity of objects.
  • Every object has a type. Using the parlance, each object is an instance of a class, in which “class” is synonymous with “type.” The most important distinguishing characteristic of a class is “What messages can you send to it?”
  • All objects of a particular type can receive the same messages. This is actually a loaded statement, as you will see later. Because an object of type “circle” is also an object of type “shape,” a circle is guaranteed to accept shape messages. This means you can write code that talks to shapes and automatically handle anything that fits the description of a shape. This substitutability is one of the powerful concepts in OOP.
  • In object-oriented programming, everything is an object. You treat everything as an object, the identifier you manipulate is actually a “reference” to an object. You might imagine this scene as a television (the object) with your remote control (the reference). As long as you’re holding this reference, you have a connection to the television, but when someone says “change the channel” or “lower the volume,” what you’re manipulating is the reference, which in turn modifies the object. If you want to move around the room and still control the television, you take the remote/reference with you, not the television.


Fundamental concepts of object-oriented programming are as follows:

 

  • Class:  A class is an object-oriented concept which is used to describe properties and behavior of a real world entity. A class is used as a blueprint to create objects of that class. For example, Dog is a class. The Dog class is used as blueprint to create objects of dogs. One object contains information of one particular dog. The Dog class contains characteristics (data members) like color, height etc and behavior (methods) like run, bark, eat etc of the dog.  
  • Object: An object is an instance of a class. Instance (object) of the Dog class is puppy (dog name).
  • Data Member: A class contains data members. Data members are used to store characteristics information of a real world entity in a class. For example, color is the data member of the Dog class.
  • Method: Methods are verbs means what an object can do? Methods are used to process data members of a class. In a class, methods are used to set, and get data member values and to perform some actions on data members.
  • Message Passing: The process by which an object sends a message (can also have data) to another object or asks the other object to invoke a method.
  • Inheritance: It’s all about reusability. In object-oriented programming, inheritance is a way to form new classes using classes that have already been defined. Subclasses are more specialized versions of a class, which inherit attributes (characteristics) and behaviors from their parent classes, and can introduce their own. For example, MountainBike, and RacingBike classes are derived from Bicycle Class.
  • Abstraction: Abstraction is the process of hiding the details and exposing only the essential features of a particular concept or object like Assembly Language is abstraction of machine language and High Level Language is abstraction of Assembly Language.
  • Polymorphism: In object-oriented programming, polymorphism (from the Greek meaning "having multiple forms") refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class Shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language.
  • Encapsulation: In object-oriented programming, encapsulation is the inclusion within a program object of all the resources need for the object to function - basically, the methods and the data.
  • Association: Association is a relationship where all object have their own lifecycle and there is no owner. Let’s take an example of Teacher and Student. Multiple students can associate with single teacher and single student can associate with multiple teachers but there is no ownership between the objects and both have their own lifecycle. Both can create and delete independently. Association represents the ability of one instance to send a message to another instance.
  • Aggregation:  When the lifetime of the part is not dependent on or not controlled by the whole, the relationship between the whole and part is Aggregation which simply means that the part continues to exist when the whole is destroyed. For example, car and stereo. Stereo is loosely coupled with car. Stereo of one car can be used in another car.
  • Composition: When the lifetime of the part is dependent on or controlled by the whole, the relationship between the whole and part is Composition which simply means that the part is no more existing when the whole is destroyed. For example, car and engine. Engine is tightly coupled with Car. Engine of Honda City cannot be used in Suzuki Mehran.

 

Simula was the first object-oriented programming language. Class keyword was also introduced in Simula first time. Java, Python, C++, Visual Basic .NET and Ruby are the most popular OOP languages today. The Java programming language is designed especially for use in distributed applications on corporate networks and the Internet. Ruby is used in many Web applications. Curl, Smalltalk, Delphi and Eiffel are also examples of object-oriented programming languages.

 

Java is 100% object-oriented programming language.

Leave a Reply

Fields with * are mandatory.
* Name:
Website:
* Comments:
 
Tags allowed: <strong> <i> <u>
* Code:
 
 
Submit   Cancel