0% found this document useful (0 votes)
7 views

OOP

The document discusses key concepts in object oriented programming including classes, objects, constructors, access modifiers, abstract classes, interfaces, traits, polymorphism, encapsulation, namespaces, destructors, static properties and methods, and method overloading and overriding.

Uploaded by

vivek30m20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

OOP

The document discusses key concepts in object oriented programming including classes, objects, constructors, access modifiers, abstract classes, interfaces, traits, polymorphism, encapsulation, namespaces, destructors, static properties and methods, and method overloading and overriding.

Uploaded by

vivek30m20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OOP: Object oriented programing.

Before oops concept we are using procedural programming but in OPPS we are using object oriented
programing.
1) codingmethodolgy/pattern/style. 2)code more modular & reusable 3)well organiz code4)easy to
debug 5)mvc are following OOPs concept
2) An object-oriented programming language is an approach that enables programmers to create
secure and flexible applications using independent objects that can be modified or reorganized
without affecting the other parts of the program.

-----------------------------------------------------------------------------------------------------------------------------------
class- A class is a blueprint for an object. It defines properties and other functions associated with the
object. It is created using the "class" keyword.
Object- An object is an instance of a class.We can create object of a class with new keyweord.

-----------------------------------------------------------------------------------------------------------------------------------
Constructor: function is a magic function it will start with double underscore.
it will call automatically while creating object of a class.
we can pass multiple parameters in Constructor and assign value in variable.

The three types of constructors in PHP are:


Default constructor: The constructor with no parameters
Parameterized constructor: The constructor with arguments is called a parameterized constructor
Copy constructor: This constructor will take the address of the other objects as a parameter

-----------------------------------------------------------------------------------------------------------------------------------
Access modifier : public [COD], protected [CD], Private [C].
note:class,object, drive
-----------------------------------------------------------------------------------------------------------------------------------
Abstract - An abstract class is a class that contains at least one abstract method.
An abstract method is a method that is declared, but not implemented in the code.
We can not create object of Abstract class.
If we declare any function of a class abstract function then class should be also abstract method.
we can use abstract class by extending the class in child class and must use abstract function in
child class otherwise it will give you a error.

Inheritance- when a class inherits properties from other classes. The class which inherits properties
and methods from the other class is known as the child class, and the class from which the properties
are inherited then it is known as the parent class. The child class uses extend keyword to inherit the
properties of the parent class, and it can also have its own properties and methods.
-----------------------------------------------------------------------------------------------------------------------------------
Interfaces- Interfaces are declared using the interface keyword.
It allows us to specify the methods of a class
All methods in the interface must be public
To extend the interface class implement operator is used
The interface makes it easy to use different classes in the same way
Classes that are defined as interfaces are not to be instantiated
----------------------------------------------------------------------------------------------------------------------------------
Traits - allow classes to inherit multiple behaviors by declaring methods in multiple classes, as PHP
doesn't support multiple inheritances; therefore, OOP traits solve this problem. Traits can have
methods with any access modifier. The trait keyword is used to create the traits.

----------------------------------------------------------------------------------------------------------------------------------
Interfaces vs. Abstract Classes
Abstract is under partial abstraction.
--It is under full abstraction.

Abstract is declared by using an abstract keyword.


--interface is declared by using the interface keyword.

Complete members of abstract classes can be static.


--The members of the interface can not be static.

abstract class a method must be declared as abstract.


--All the methods in the interface are abstract by default.

The abstract methods can be protected or public.


--The interface methods must be public.
----------------------------------------------------------------------------------------------------------------------------------

Static - The static keyword is a non-access modifier that defines the static variables and methods
common to all objects. The static properties and methods can be used directly without creating an
instance of the class.

If we take any example, All the students in the same school have a common property of school name;
therefore, we can make the variable school name static.

-----------------------------------------------------------------------------------------------------------------------------------
NameSpace- namespaces prevent conflict between the classes with the same name so they can't be
reused again. A namespace contains a regular valid PHP code and affects codes like interface,
constants, and classes.

The namespace keyword is used for the declaration of the namespace at the top of the file
-----------------------------------------------------------------------------------------------------------------------------------
destructor : A destructor is called when the object is destructed or the script is stopped or exited.
If you create a __destruct() function, PHP will automatically call this function at the end of the script.

-----------------------------------------------------------------------------------------------------------------------------------
Polymorphism : we can use same function in diffrent classes but the behavior is diffrent for all classes
if we creating calculate fucntion and want to add subtraction multiplication we can use same function
for this is call Polymorphism.
-----------------------------------------------------------------------------------------------------------------------------------
Encaptulation- In simple mean of Encaptulation is how we are hidding or seting acces level of our
varible & menthod information.
so it will not use in a particular class or in function is call Encaptulation.

if we set private to a class variable we can not access directly creating object of class --we need to
geeter fucntion to access.
if we extend this and try to acces in child then it will not give access we.

if paraent class varible is protected and child class a method or varible is private and we are
overiddding method or varible with private acees it will not acces.
we neet to set to low like protected or public.x

encapsulation VS abstraction
Encapsulation is a way of protecting the data. Abstraction is a way of hiding unnecessary
information.
---------------------------------------------------------------------------------------------------------------------------------------
Singletone class : use for not create instance more than one time.
buy using private static varible, private constroctor static method that will be return single instance.

Method Overloading & Method Overriding - add($a, $b=0){} paramiter add(15);/add(15,6);


And methos overriding is declare same name fucntion in another class and overidding functionality of
method.

You might also like