Studyrightnow, Study Right Now, Right Now Study, SRN

Phone: 00000
Email: Abc@gamil.com

Introduction Of OOPs (Php)

  • Introduction Of OOPs (Php)

    PHP is an open source language, which allows programmers to quickly develop programs mainly used for web development, using both programming techniques; procedural and objected-oriented.

    Procedural programming

    In procedural programming techniques, functions (methods) is the main convern, the flow of the program jumps to the function (method) which we call and executes the code that is define in the body of the method, then returns the result in the main flow of the program.

    Object-oriented programming (OOP)


    OOP is an approach to develop a software that uses real world objects such as employees, cars, bank accounts, etc and methods rather than linear concepts of procedures and tasks (procedural programming) to accomplish programmatic goals. A class contains or defines the properties and methods of a real world object. A method specifies an operation to describe how the operation should be worked.

    Object-oriented programming is a programming style in which pragrammers can make a group all of the variables and functions (methods) to complete a particular task, into a single class. Object-oriented programming is considered to be more advanced and effective than procedural programming because of better code organization or structure, provides modularity.

    We can imagine a car made of different objects like wheel, engine, seats etc. In the same way Object Oriented Programming Technique works which assume everything as an object and implement a software using different objects.
     

    Advantages of OOP

    Object Oriented Programming (OOP) has some advantages over procedural programming; you can study them below:

    Modularity

    OOP provides a clear modular structure for programs. Modularity refers to the concept of making multiple modules first and then linking and combining them to form a complete system. Modularity enables re-usability and minimizes duplication.

    Reusability

    In object oriented programming, the concept of inheritance provide reusability, means we can add additional features or code to an existing class without modifying it to perform a specific task according to the need of our application.

    Information-hiding

    Information hiding is the technique used for hiding the details of an object or function to reduce the external complexity and makes the object or function easier to use. Encapsulation is a common technique used to implement information hiding.

    Debugging

    If programmers use OOP technique then its easier to fix problems because the structure is based on the module (class) that is independent from other pieces of code. So modifying one piece of code doesn’t impact other pieces of code in the application.

    Object Oriented Concepts

    Below is the introduction of the main features or terms in Object Oriented Programming. We will discuss these step by step.

    • Class − Class is a user defined data type, which is a collection of local functions and local variables. You can say, a class is a template for making many instances of the same kind of object. To define a class, the class keyword is used, followed by a name and a code block with curly braces.

    • Object − An instance of a class is called object. You define a class once and then make many objects that belong to it.

    • Member Variable − In PHP, class member variables are called properties or attributes of the object once an object is created. They are defined by the keywords public, protected or private, before a normal variable declaration. These are the variables defined inside a class.

    • Member function − The data defined by the keywords public, protected or private, before a normal variable declaration, will be invisible to the outside of the class and can be accessed via member functions. These are the function defined inside a class and are used to access object data.
      Inheritance − In object oriented programming, by Inheritance we can use properties and methods of an existing class to another class. Inheritance is very useful in case of reusability of the methods and properties.

    • Parent Or Super class − A class that is inherited by another class. This is also called a base class or super class.

    • Derived Or Child Class − A class that inherits from another class. This is also called a subclass or derived class.

    • Polymorphism − This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it take different number of arguments and can do different task.

    • Overloading Overloading is defining functions that have similar signatures, yet have different parameters. Similarly functions can also be overloaded with different implementation.

    • Data Abstraction − Data Abstraction means any representation of data in which the implementation details are hidden or abstracted. Abstraction provides a generalized (understandable) view of your classes or object by providing relevant information.

    • Encapsulation − Encapsulation is a concept where we encapsulate (or hide) all the data and member functions together to form an object. So encapsulation is known as data hiding and it is the main advantage of it.

    • Constructor And Destructor − To create and initialize a class object in a single step, PHP provides a special method called as Constructor, which is used to construct the object by assigning the required property values while creating the object. And for destroying the object Destructor method is used.