Object Oriented Programming
A description of Object Oriented Programming
Object Oriented Programming
Object-oriented programming (OOP) is a style of programming that focuses on using objects to design and build applications.
Objects:
Objects have states and behaviors. An object is a self-contained component that contains properties and methods needed to make a certain type of data useful. An object’s properties are what it knows and its methods are what it can do.
Classes and instances:
A class can be defined as a blue print that describes the behaviors and states that object of its type support. Every object is built from a class. Each class should be designed and programmed to accomplish one, and only one, thing. Because each class is designed to have only a single responsibility, many classes are used to build an entire application. An instance is a specific object built from a specific class. It is assigned to a reference variable that is used to access all of the instance’s properties and methods. When you make a new instance the process is called instantiation. So, a class is like a blue print for a house. You can use the same blue print to build many houses. Instantiation is following what is on the blueprint. You can instantiate as many instances of a class as you want.
There are four major principles of object oriented programming: 1. Encapsulation 2. Abstraction 3. Inheritance 4. Polymorphism
1.Encapsulation
Encapsulation means that the internal representation of an object is generally hidden from view outside of the object’s definition. Typically, only the object’s own methods can directly inspect or manipulate its fields.Encapsulation is the hiding of data implementation by restricting access to accessors and mutators.
An accessor is a method that is used to ask an object about itself. In OOP, these are usually in the form of properties, which have a get method, which is an accessor method. However, accessor methods are not restricted to properties and can be any public method that gives information about the state of the object.
A Mutator is public method that is used to modify the state of an object, while hiding the implementation of exactly how the data gets modified. It’s the set method that lets the caller modify the member data behind the scenes.
2.Abstraction
Data abstraction is the development of classes, objects, types in terms of their interfaces and functionality, instead of their implementation details.Its the development of a software object to represent an object we can find in the real world. Data abstraction is nothing more than the implementation of an object that contains the same essential properties and actions we can find in the original object we are representing.
3.Inheritance
Inheritance is the process that enables one class to acquire the properties (methods and variables) of another. The class inheriting the properties of another is the subclass (also called derived class, or child class); the class whose properties are inherited is the superclass (base class, or parent class). Inheritance allows child classes to inherit the characteristics of an existing parent class. The child class can be used to modify existing behaviour of the parent class.
4.Polymorphism
Polymorphism means one name, many forms. Polymorphism occurs when there is a hierarchy of classes related to each other through inheritance.