Use of Object Oriented Programming Style

Updated on March 1, 2018
Lalit Bunkar profile image

Lalit Kumar is a software developer and programmer and has been developing websites and softwares since 2008.

What is OOPs ?

Object Oriented Programming or OOPs is the modern programming style which supports the creation of large and complex software architecture in easy and maintainable manner.

OOPs represent a major shift from traditional procedural programming in which we use data and functions. The data stored in variables and passed to defined function which in turn perform some action and modify it or create new data. We can define the traditional procedural programming style as a list of instructions which gets executed in an orderly manner defined by control flow statements and functions.

For simple programming tasks, use of procedural programming style is well suited but as the program becomes complex and software architecture becomes large, object oriented programming is suitable to create modular designs and patterns.

Data and functions are very much separated in procedural programming style whereas in OOPs, data and functions are tied together in an entity called object. We call functions of an object to modify its data. These data in OOPs are known as properties and functions used to modify properties are called methods.

Major Benefits Of Using OOPs

1. Encapsulation : Objects created in OOPs are able to hide certain parts of code from programmer. This prevents unintentional modification in the code which may cause unwanted outcomes.

2. Code Reuse : Objects created in OOPs can easily be reused in other programs.

3. Software Maintenance : Code written in OOPs is easy to debug and maintain.

4. Design Benefits : OOPs needs extensive design planning which certainly provide design benefits over traditional style.

Core OOPs Concepts

  • Abstraction : This concept includes hiding the internal details of program and implementing things in easy way. In OOPs there are many ways to achieve this including encapsulation and inheritance.
  • Encapsulation : In object oriented programming style, we use Encapsulation to implement abstraction. Encapsulation is used for access restriction to property or method of class. We use access modifiers to implement these access restriction. There are 3 access modifiers are available private, public and protected.
  • Polymorphism : We can define many methods in a class with same name but different types and number of variable it takes as inputs. This is the concept of Polymorphism where an object behaves differently in different situations. There are two types of polymorphism – compile time polymorphism and runtime polymorphism.
  • Inheritance : Inheritance encourage code reuse in programming. This is the concept in which we define a class which extends properties and methods from another class. This way new class have all the properties of class from which it is extended and you can add extra properties and methods in your new class.
  • Association : Association is the OOPS concept which defines the relationship between two objects. It defines one to many or many to one relation between two objects.

Access Modifiers

1. Private : Properties and methods defined with private access modifiers can only be accessed by class in which these are defined.

2. Public : Available everywhere on object instantiation.

3. Protected : Available within class itself and in the derived class.

OOPs Common Elements

  • Class : Behaviour and contents of an object are defined in a class. So a class is a set of instruction to create an objects.
  • Property : Variables defined inside a class are known as properties. These variables contains data.
  • Methods : Functions defined inside a class, which perform some action on properties and inputs are called methods.
  • Object : Object is a specimen of class. It is a self-contained entity which consists of methods and properties to make a particular type of data useful.

Message Passing In OOPs

All objects created from class, communicate with each other by sending and receiving information. Objects pass a request message to execute a procedure to other object which in turn generate the desired result. The message which objects pass to each other contains name of the object, name of method and information to be sent like variables and user inputs.

Explaining OOPs...

Object-oriented programming (OOP) is a programming language paradigm structured around objects & data rather than actions & logic. A traditional procedural program is organized to take input data, process it and produces result. Program was centralized around logic rather than data. In object oriented programming, we concentrate on objects and its manipulation and not on logic which do it. OOPs programmer choose many things as objects for illustration like Car, Dog, Human, Building etc.

The first step in OOPs is data modelling, which includes identification of objects involved, ways to manipulate them and relation between all objects. Data modelling is a planning phase and requires extensive care. Once all objects involved in program are identified, we put a mechanism to create those objects. This mechanism is known as class. A class contains data or properties and methods which are logical sequence to manipulate data. All methods should be distinct in nature and should not repeat the logic already defined in other methods.

More terms used in OOPs..

  • Interfaces : Interfaces contains the protocols which defines methods a class must contain. Interfaces are defined just like a class and used by programmer to follow pre-defined rules from original creator to use APIs.
  • Static Class, Property, Method : Static class or property or method contains value which are common for all objects and can be accessed without creating objects.

© 2018 Lalit Kumar

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, owlcation.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://owlcation.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)