Web Programming – The Object Oriented Programming (OOP) approach

Web programming is an aspect of website development, and the role of the web programmer is very important, as is the role of website designers in the website design aspect of website development. Programming languages ​​are developed from machine languages ​​to low-level languages ​​and then to high-level languages. The high-level language, which is a language close to the natural language (the language we speak), is written using certain approaches. The monolithic and structural programming methods are remarkable. With the monolithic style, you write an entire program in a single block. In structured programming method, a program is divided into blocks of codes called modules, with each module performing a specific task. BASIC, COBOL, PASCAL, C and DBASE running on the MS-DOS platform could be written using either method.

After the revolution of the Windows operating system, it became possible to write programs using a more advanced structured programming method than the type used on the MS-DOS platform. This is the Object Oriented Programming (OOP) approach where a program is divided into classes and each class is divided into functions or methods where each function provides a specific service. C ++ and Java are typical examples of Object Oriented Programming (OOP) language originally developed for non-web solutions. As web application preference grew more and more in line with the historical development of the Internet and the historical development of the Web, the need to improve scripting languages ​​continued to arise and one of the ways they went about it was by making scripts for object-oriented. Java Applet and PHP (Hypertext Preprocessor) are examples of Object Oriented Programming (OOP) language for web solutions. Originally, PHP was not object-oriented, but it was completely upgraded to an Object-Oriented Programming Language (OOP), demonstrating the 3 pillars of Object-Oriented Programming (OOP) – Encapsulation, Inheritance and Polymorphism. Thus, it is possible to write scripts on the server side in an object-oriented manner.

Object Oriented Programming (OOP) structures program into classes and functions or methods. To use a class and access the services provided by each feature, you must create an instance of the class. When an instance is created, an object that is held by an object variable is produced. It is this object that is now used to access each feature and make use of its service. The syntax for class instantiation statement for object creation varies from language to language. In PHP, you use the new keyword. For example, if you have a namesake class and you want to instantiate it and use the object to access the select_records () function in the class, you walk around it this way-

$ cust = new Customer ();

$ cust-> select_records ();

The first line created an instance of class customer and an object contained by an object variable $ cust. The second line accesses the service provided by the select_records () function with the $ cust object variable. Java also uses the new keyword to create objects, but the use of the keyword in C ++ is different where it is used by a cursor variable during dynamic memory allocation. I previously mentioned the three pillars of Object Oriented Programming (OOP) encapsulation, inheritance and polymorphism. They are the integrated features of PHP. Encapsulation is the process of hiding every detail of an object that does not contribute to its essential properties. This is accomplished by making all instance variables in a class private, so that only the class member functions can access its private instance variables. Inheritance is a situation where a class derives a set of attributes and related behaviors from a parent class. The parent class is called super class or base class and the inheriting class is called subclass. The superclass member variables become subclass member variables (derived class). In PHP you use the keyword expanded to implement inheritance like for example Java

class customer extends products

Polymorphism is an extension of heritage. It is a situation where a subclass overrides a function in the superclass. When a function or method is overridden, the name and signature of the function in the superclass are retained by the parent function in the subclass, but a change in the function code occurs.

Another important feature of Object Oriented Programming (OOP) language is constructor. A constructor is a function or method that bears the same name as its class name, and it is used for initializing member variables and invoked as soon as the class is instantiated unlike other member functions invoked using the object variable only. At this point, let’s use data submission with, for example, fixed assets form for further illustration. Your PHP script should retrieve data from the form, connect to the database, print custom error messages, and insert data into the database table. Using the Object Oriented Programming (OOP) approach, you need 4 features of the class-

  1. The constructor – to retrieve the posted data from the form.
  2. A function to connect to MySQL database.
  3. A function to insert record into the database using the INSERT SQL statement.
  4. A feature for printing custom error messages.

Because your program is in an organized form, it is easier to understand and debug. This will be greatly appreciated when dealing with long and complex manuscripts such as those that contain basic stock broking principles. Within the boundaries of the structured programming functions in the non-object oriented programming languages ​​in BASIC, COBOL, PASCAL, etc., you can also organize the program by dividing it into less manageable modules. However, they lack the encapsulation, inheritance, and polymorphism of object-oriented programming (OOP), demonstrating a major advantage of the object-oriented programming (OOP) approach.

Copyright reserved.