AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=905&pId=-1
Introducing Object Oriented Programming
page
by Joydip Kanjilal
Feedback
Average Rating: 
Views (Total / Last 10 Days): 23626/ 33

What is Object Oriented Programming?

The concept of Object Oriented Programming (OOP) was invented based on the necessity to remove the flaws that were encountered using the structured programming methodology. Unlike the traditional top down approach followed by structured programming languages, OOP follows a bottom up approach.  OOP is modeled around data and objects rather than actions and logic that the structured programming paradigm used to follow.

OOP allows decomposition of a problem into a number of entities called objects.  Then it builds data and functions around these objects.  The basic idea of OOP is centered on classes and objects.

A system is designed by defining the objects that will exist and interact within the system.

The basic benefits of OOP are the following.

·         Easier Maintainability

·         Better Analysis and Design of Complex Applications

·         Reusability

Some of the popular Object Oriented Languages are the following.

·         C++

·         Java

·         C#

·         Smalltalk

·         Ada

·         Simula

What is Data Modeling?

The first step in designing an Object Oriented System is identifying the objects in the system and their relationships.  This process is also referred to as Data Modeling.

Object Oriented Programming Terminologies

Object Oriented Programming (OOP) emphasizes the following concepts

Class

A class may be defined as a self contained unit that encapsulates a collection of data and methods that operate on the data.  Basically there are three access modifiers that are used in a class.  They are public, private and protected.  A public member is both accessible and inheritable.

A private member cannot be accessed from the outside world; nor can it be inherited.  A protected member is inheritable, but cannot be accessed from outside of the class hierarchy.  We can say that a protected member is an inheritable private member.

Object

An object may be defined as an instance of a class that can send and receive messages and process data.  The software objects are used to model the real-world objects that are common in every day life.  Real-world objects share two characteristics:

·         State

·         Behavior

Method

A method is a way of operating on an object.  A method can have either the private, public or protected visibility label.  The visibility label of a member of the class indicates how much of the class is exposed to the outside world.

Inheritance

This is a feature by virtue of which a child class inherits its parent.  A subclass inherits all the members of its base, except those that are private.  A sub class may have one or more base classes, i.e. it can be inherited from one or more bases.  Such type of inheritance is known as Multiple Inheritance.  A sub class can also extend the behavior of its inherited members and add new members.  Here it needs to be mentioned that there are two relationships in OOPS- "has-a" and "is-a."  The former indicates a composition, while the later indicates inheritance.  Inheritance offers the following benefits:

·         Reusability

·         Implement Abstract Data Types

Encapsulation

Encapsulation is a property of OOPS that combines the data and the members of a class inside a unit resulting in an isolation of the unit from the external world.  It exposes only the functional details, but hides the implementation details of the class.

The benefits of encapsulation:

·         Modularity

·         Information-hiding

Abstraction

Abstraction is the ability of a program to ignore the details of an object's (sub)class and work at a more generic level when appropriate.  Abstraction is a concept or idea that is not related to any particular instance.  It is the process of identifying common patterns that can have systematic variations.  The purpose of an Abstract class is to provide a common definition that the subclasses can share.

Polymorphism

Polymorphism is behavior that varies depending on the class in which the behavior is invoked.  In other words, two or more classes can react differently to the same message.  Polymorphism is the ability of the objects to react differently when presented with different information, known as parameters.  In a functional programming language the only way to complete two different tasks is to have two functions with different names.  Object-oriented languages, which include Java, allow different methods to be run depending on what types of parameters are specified.  The word Polymorphism is derived from two Greek words, namely Poly and Morphos.  Poly indicates many and Morphos indicates forms.  Therefore, it is the existence of the same thing in different forms.

 

Polymorphism can be of the following types.

·         Static or Compile Time Polymorphism

·         Dynamic or Runtime Polymorphism

Static Polymorphism is the polymorphism that occurs at compile time.  In static polymorphism the binding or that association of an object of a class and its member occurs at compile time. Overloaded constructors of a class and polymorphic non-virtual methods are classic examples of Static or Compile Time Polymorphism.  Dynamic Polymorphism refers to the polymorphism that occurs at run time.  It is achieved using Virtual Methods.  In dynamic polymorphism the binding or that association of an object of a class and its member occurs at run time.

Instantiation

Instantiation is the ability of a non-abstract class to create a finite number of objects.  An instance of a class is commonly known as an object.

Sealed and Final Classes

A sealed class in C# or a final class in Java is one that can be instantiated, but not inherited.

Message

Objects can interact and communicate with each other in the same or across different systems using messages.  A message is comprised of the addressee, the method name and the parameters.  When an object wants to invoke a method on another object, it sends the later a message.

Interface

In general, an interface is a device or a system that unrelated entities use to interact.  According to this definition, a remote control is an interface between you and a television set, the English language is an interface between two people, and the protocol of behavior enforced in the military is the interface between individuals of different ranks.  You use an interface to define a protocol of behavior that can be implemented by any class anywhere in the class hierarchy.

Suggested Readings
Conclusion

This article was not designed with any particular programming language in mind; rather it focused on the general principles of this excellent programming paradigm that took the programming fraternity by storm a decade ago and revolutionized the design of and the approach towards computer programming around the globe.  Object Oriented Programming, if used correctly, can lead to the development of very robust, easily expandable and maintainable systems.


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 8:14:23 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search