Polymorphism, as its name implies, comes in a variety of forms. OOP allows for the use of a variety of techniques I. Simply expressed, they have to do with how methods are used, and how different methods operate for different objects. Method Overriding and Method Overloading are two ways that polymorphic methods allow for different actions to be done.
The benefits of Polymorphism are:
Objects of different types can be passed through the same interface
Method Overriding:- Overriding is used in the polymorphism of runtime. By overriding a parent class’s method, a child class can implement a different method. In the case of our dogs, we may prefer a specific type of bark that is distinct from the generic type of dog (TrackingDog).
Method Overloading:- Overloading is used at the polymorphic build time. Although methods and functions may have the same name, the call method has its own set of arguments. Different results may be obtained depending on the number of parameters entered.
Example:- There are no parameters supplied to the updateAttendance() method. The count will be added one day. When the updateAttendance(4) argument is used, the x xupdateAttendance(x) parameter is used, and four days are added to the total.
Abstraction in OOP allows information/access about how codes are applied to be concealed, allowing just the required access. These details may be found in the object definitions. A famous example is the counting approach that works with list items. One thing to keep in mind is that, given the same OOP concept, all Python I data types and structures are objects. In this sense, a list is a class that has methods for completing tasks.
What is the Function of Abstraction?
Abstraction use simpler high-level instruments to get access to a complex object:
Using simple things to represent complexity
Hide complex details from user
Abstraction also serves a significant security role. We only present selected data items and provide data access via classes and methods to protect the data from being exposed. In the case of an automobile, an open gas tank would make it impossible to continue driving.
There are some benefits of abstraction which is mention below:
In OOP, the concept of inheritance allows a class to accept or have the properties of another class (inherited). A sub-class or derived class is a class that inherits the characteristics/methods of another class. Heritage reduces code redundancy, allowing the class to use other class methods without having to rewrite the code. This allows for dynamic programming using the main class’s methods (also called the parent class). A subclass has the same properties as a primary class, but it can also have additional methods that are either completely independent or not present in the main class.
What is the Function of Inheritance?
Children’s classes may be built to enhance the parent’s class functionality and add more characteristics once essential properties and behaviors have been defined in the parent’s class.
This distinction is demonstrated by creating a parent class child class(HerdingDog) (Dog) and then adding a single herd() behaviour.
The following code shows how the child class (HerdingDog) inherits a parent class method (bark) (Dog), and the child class adds an extra method herd().
When the code uses the fluffy.bark() function, the method bark() travels up the child’s chain to find out where the bark method is declared.
Computer programming skills is in high demand in today’s technology culture for programming. Understanding object-oriented programming may be useful in the creation and management of software systems (OOP). This article covers the core concepts of OOP and illustrates them with simple examples.
What is Object-oriented programming (OOP)?
Object-oriented programming is the process of integrating variables (properties) and functions (methods) into a single object. These products are organized into classes that may be mixed and matched. OOP allows you to think about the objects in a program’s code as well as the various actions that go along with them.
What are the principles of Object-oriented programming (OOP)?
Encapsulation, Abstraction, Inheritance, and Polymorphism are the four basic concepts of object-oriented programming. Although these concepts appear to be extremely complicated, understanding the broad framework of how they work is beneficial. The four basic hypotheses are as follows:
Inheritance: child classes inherit data and behaviors from parent class
Encapsulation: containing information in an object, exposing only selected information
Abstraction: only exposing high level public methods for accessing an object
A set of attribute values plus an attribute identifier make up an attribute. The attribute identifier, often known as the attribute name, is a string that uniquely identifies a property. The content of an attribute is its value, and its type is not limited to that of a string. When you wish to define a specific attribute for retrieval, searches, or update, you use an attribute name. Operations that yield characteristics also return names (such as when you perform reads or searches in the directory). You must be aware of specific directory server characteristics while using attribute names so that the result does not surprise you. These characteristics are discussed in the next section.
Uses of Name Attribute
The name attribute specifies a name for an HTML element.
For a <form> element, the name attribute is used as a reference when the data is submitted.
For an <iframe> element, the name attribute can be used to target a form submission.
For a <map> element, the name attribute is associated with the <img>‘s usemap attribute and creates a relationship between the image and the map.
For a <meta> element, the name attribute specifies a name for the information/value of the content attribute.
For a <param> element, the name attribute is used together with the value attribute to specify parameters for the plugin specified with the <object> tag.
$_GET is a global variable that is used to collect data from an HTML form after it has been submitted. The data is visible in the query string when the form uses method get to transmit data, thus the values are not concealed. The values in the URL are stored in the $_GET super global array variable.
Right now, we’re just seeing half of the rationale. We’ve generated a linked image of Nainital Lake in the preceding code, which will take us to the picture.php page and provide the parameters name=”Nainilake” and city=”Nainital” to it.
That is, if we click on the little image of Nainital Lake, we will be brought to the next page picture.php, where the parameters will be displayed. These arguments will be given to the next page using the get method, and they will be shown in the address bar, as get is the default way. When we wish to transmit data to an address, we use a question mark (?) to connect them to the address.
The address has the name=Nainilake parameter connected to it. If we wish to add more values, we may do so by appending an ampersand (&) after each key-value combination, similar to how city=Nainital is appended after the name parameter. Now, when you click on the image of Nainital Lake, we want the picture.php page to appear, along with the value of the parameter.
It’s a global variable that’s used to collect data from the HTML form after it’s been submitted. Because the data is not accessible in the query string when a form uses method post to transfer data, security standards are maintained in this manner.
Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to the file itself in this case. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_POST:
We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables. We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables.
$_REQUEST is a super global variable that’s used to collect data when an HTML form is submitted. Because $_POST and $_GET accomplish the same purpose and are extensively used, $_REQUEST is rarely used.
Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to this file in our example. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_REQUEST:
We’ve constructed a form in the above code that accepts the user’s name as input and prints it when the submit button is pressed. Because we alter the data on the same page using PHP code, we transfer the data received in the form to the same page using the $_SERVER[‘PHP SELF’] element as stated in the action attribute. The $_REQUEST super global array variable is used to obtain the data.
It’s a super global variable in PHP that keeps track of headers, paths, and script locations. Some of these components are used to obtain data from the $_SERVER super global variables.
To retrieve some information, we used the $_SERVER components in the code above. Using the ‘PHP SELF’ element, we retrieve the current file name that is being worked on. Then, using the ‘SERVER NAME’ attribute, we retrieve the current server name. Then we use ‘HTTP HOST’ to retrieve the host name.
The following table lists the most important elements that can go inside $_SERVER:
Returns the filename of the currently executing script
Returns the version of the Common Gateway Interface (CGI) the server is using
Returns the IP address of the host server
Returns the name of the host server (such as www.w3schools.com)
Returns the server identification string (such as Apache/2.2.24)
Returns the name and revision of the information protocol (such as HTTP/1.1)
Returns the request method used to access the page (such as POST)
Returns the timestamp of the start of the request (such as 1377687496)
Returns the query string if the page is accessed via a query string
Returns the Accept header from the current request
Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1)
Returns the Host header from the current request
Returns the complete URL of the current page (not reliable because not all user-agents support it)
Is the script queried through a secure HTTP protocol
Returns the IP address from where the user is viewing the current page
Returns the Host name from where the user is viewing the current page
Returns the port being used on the user’s machine to communicate with the web server
Returns the absolute pathname of the currently executing script
Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as email@example.com)
Returns the port on the server machine being used by the web server for communication (such as 80)
Returns the server version and virtual host name which are added to server-generated pages
Returns the file system based path to the current script
$GLOBALS is a super global variable that may be accessed from anywhere in the PHP script. All global variables are stored in the array $GLOBALS, where index is the global variable name that may be retrieved.
All global variables are stored in an array named $GLOBALS[index] in PHP. The variable’s name is stored in the index.
The example below shows how to use the super global variable $GLOBALS:
Two global variables, $x and $y, are declared in the above code and are given a value. Then, in the GLOBAL array, a function multiplication() is written to multiply the values of $x and $y and store the result in another variable $z.