INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Object oriented programming

Creating a computer program as a collection of modules which are abstractions of real world objects.

OOP was invented to remove flaws encountered in the procedural approach, OOP allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects.

Features of OOP

  • Programs are divided into objects.
  • Data structures are designed such that they characterize the objects.
  • Data is hidden and cannot be accessed by external functions.
  • Objects communicate with each other through message passing.
  • Follow bottom-up approach in program design (It refers to a style of programming where an application is constructed starting with existing primitives of the programming language, and constructing gradually more and more complicated features, until all of the application has been written.).

Procedure oriented programming

Conventional programming, using high level languages such as COBOL, FORTRAN and C, is commonly known as procedure-oriented programming (POP), in this approach the problem is viewed as a sequence of things to be done. A number of functions are written to accomplish these tasks.

POP basically consists of writing a list of instructions for the computer to follow and organizing these instructions into groups known as functions. Normally a flowchart is used to organize these instructions and represent the flow of control from one action to another.

Features of a POP

  • Use of algorithms (flowchart).
  •  Large programs are divided into smaller programs known as functions.
  • Most of the functions share global data.
  • Data move openly around the system from function to function.
  • Employs a top-down approach in program design.( It refers to a style of programming where an application is constructed starting with a high-level description of what it is supposed to do, and breaking the specification down into simpler and simpler pieces, until a level has been reached that corresponds to the primitives of the programming language to be used).

Basic concepts of OOP

Concepts mainly used in OOP include

  • Objects
  • Classes
  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Message passing
  1. Objects

These are basic run-time (the length of time a program takes to run.) entities in an object oriented system they may represent a person, place, bank account a table of data or any item that the program has to handle. Objects also represent user defined data such as vectors, time and lists.

The concept of object is used simplify the representation of complex real world structures as software structures in the computer.

Objects enable abstraction of the real world and structural representation in the computer.

  1. Classes

A class is a collection of objects of similar type classes can be concretely defined example apples, banana, and mangos are members of a class fruit. Classes are user-defined data types and behave like the built-in types of a programming language.

Types of classes

  • Abstract class
  • Concrete class
  • Active Class
  1. Abstraction

A concept important for simplification of representation of complex structures

Representation of complex structure by simpler structure that hide the complex details

In computer science abstraction has enabled the development of various levels of programming languages that enable simplify the definition of the program and data structures that would be difficult to do with the natural language of the computer.

This has simplified the development of the large programs that provide real world solutions –programs that would be difficult to implement with the machine language

  1. Encapsulation

The containment or packaging of data and functions that use the data in a program module. Encapsulation protects the data from modification by functions external to the object.

This is implemented by definition of abstract structure referred to as class that represents the type of object.

Facilitates information hiding which is an important characteristic that enables create reliable programs

  • Inheritance

Is the process by which objects of one class acquire the properties of objects of another class.

This concept is used in object oriented programming to describe the relationship between types of objects where one object is a sub type of another.

Inheritance is one of the approach to employing reuse in programming.

Reuse by inheritance enables to take an existing type of object, clone it and then make additions and modifications to the clone.

Types of inheritance

  • Single inheritance – A sub type of an object inherits from only one super type.
    • Multiple inheritance – A sub type of an object inherits from two or more super types.
    • Repeated inheritance – A special multiple inheritance where the super types of a subtype inherit from another super type.
    • Selective inheritance – Limited inheritance of a subtype from its super type.

Restricting access to some details in the super type

  • Polymorphism

Polymorphism is a Greek term which means ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends upon the types of data used in operation.

Types of polymorphism

Overloading- This is changing the implementation of a method inherited from a parent class. The name, arguments and the return type remain the same but the action differs

Overriding- This means using the same name for different methods in a class.

  • Message passing

This refers to the communication between objects. Objects communicate with one another by sending and receiving information.

Leave a comment

Design a site like this with WordPress.com
Get started