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.
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.
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.
Questions & Answers
Question: What are the usages of OOP?
Answer: Object-Oriented Programming supports features such as Inheritance, Encapsulation, Polymorphism, Abstraction. Object-oriented programming is a modern way of software development. So all modern software you see is developed using OOP.
Question: What do I need to start coding in Java?
Answer: You only need a good PC with at least 4GB RAM & 100 GB HDD. Install java which is available for free.
Question: Application of OOP?
Answer: Object oriented programming is modern way of software development. So all modern software you see are developed using OOP.
Question: what is the difference between object oriented programming laguage and non object oriented programming language?
Answer: Non-object oriented programming is called procedural programming languages. Object Oriented Programming supports features such as Inheritance, Encapsulation, Polymorphism, Abstraction which the above languages do not support.
© 2018 Lalit Kumar
Mark Gatere on November 04, 2019:
This information was so helpful.
Thank you so much Sir Lalit Kumar.