Web Programming - OOP Approach
Upcoming SlideShare
Loading in...5

Web Programming - OOP Approach



A Fresh Web Design programmers specialize in custom, dynamic, interactive websites for midsized and small businesses.

A Fresh Web Design programmers specialize in custom, dynamic, interactive websites for midsized and small businesses.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds


Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Web Programming - OOP Approach Web Programming - OOP Approach Document Transcript

    • ==== ====A Fresh Web Design programmers specialize in custom, dynamic, interactive websites for mid-sized and small businesses.http://www.afreshwebdesignstlouis.com/services.html?category=2==== ====Web programming is an aspect of web site development and the role of web programmer is verysignificant just as web designers role in web design aspect of web site development.Programming languages have developed from machine language to low-level language and thento high-level language. The high-level language which is a language close to natural language (thelanguage we speak) is written using certain approaches. Notable are the monolithic and structuralprogramming approaches. With the monolithic style, you write a whole program in one singleblock. In structured programming approach, a program is divided into blocks of codes calledmodules with each module performing a specific task. BASIC, COBOL, PASCAL, C, and DBASEthat ran on MS-DOS platform could be written using both approaches.Following the revolution of windows operating system, it became possible to write programs usinga more advanced structured programming approach than the type used on MS-DOS platform. Thisis the Object-Oriented Programming (OOP) approach where a program is divided into classes andeach class is subdivided into functions or methods with each function providing a specific service.C++ and Java are typical examples of Object-Oriented Programming (OOP) languages whichwere originally developed for non-web solutions. As the preference for web applications grewmore and more according to the historical development of the internet and the historicaldevelopment of web, the need to improve on scripting languages continued to arise and one of theways they embarked on it was by making scripts Object-Oriented. Java applet and PHP (HypertextPreprocessor) are examples of Object-Oriented Programming (OOP) languages for web solutions.PHP was originally non Object-Oriented but it has been fully upgraded to an Object-OrientedProgramming language (OOP) demonstrating the 3 pillars of Object-Oriented Programming (OOP)- Encapsulation, Inheritance, and Polymorphism. Thus, it is possible to write server-side scripts inan Object-Oriented fashion.Object-Oriented Programming (OOP) structures program into classes and functions or methods.To use a class and access the services rendered by each function, you must create an instance ofthe class. When an instance is created, an object is produced which is held by an object variable.It is this object that will now be used to access each function and make use of its service. Thesyntax of class instantiation statement for object creation varies from language to language. InPHP, you use the new keyword. For instance, if you have a class with name customer and youwant to instantiate it and use the object to access function select_records() in the class, you goabout it this way-$cust = new customer();$cust->select_records();
    • The first line created an instance of class customer and an object held by object variable $cust.The second line accesses the service provided by function select_records() with the objectvariable $cust. Java too uses the new keyword for object creation but the application of thekeyword in C++ is different where it is used by a pointer variable during dynamic memoryallocation. I mentioned earlier the three pillars of Object-Oriented Programming (OOP)-Encapsulation, Inheritance, and Polymorphism. They are the integral features of PHP.Encapsulation is the process of hiding all the details of an object that do not contribute to itsessential characteristics. This is achieved by making all instance variables of a class private sothat only the member functions of the class can access its private instance variables. Inheritanceis a situation in which a class derives a set of attributes and related behavior from a parent class.The parent class is called super class or base class and the inheriting class is called sub class.The member variables of the super class become member variables of the sub class (derivedclass). In PHP, you use the keyword extends to implement inheritance just like Java, for exampleclass customer extends productsPolymorphism is an extension of inheritance. It is a situation when a sub class overrides a functionin the super class. When a function or method is overridden, the name and the signature of thefunction in the super class are retained by the overriding function in the sub class but there is achange in the function code.Another important feature of Object-oriented Programming (OOP) language is constructor. Aconstructor is a function or method bearing the same name as its class name and it is used forinitialization of member variables and invoked as soon as the class is instantiated unlike othermember functions that are invoked only with the use of the object variable. At this point, let us usesubmission of data with, for instance, fixed asset register form for further illustration. Your PHPscript needs to retrieve data posted from the form, connect to database, print custom errormessages and insert data into the database table. Using the Object-Oriented Programming (OOP)approach, you need 4 functions in the class-The constructor- to retrieve the posted data from the form.A function to connect to MySQL database.A function to insert record to the database using the INSERT SQL statement.A function to print custom error messages.Because your program is in an organized form, it is easier to understand and debug. This will behighly appreciated when dealing with long and complex scripts like those incorporating basic stockbroking principles. Within the limit of the structured programming capabilities of the non Object-Oriented Programming languages of BASIC, COBOL, PASCAL etc, you could organize programtoo by dividing it into smaller manageable modules. However, they lack the encapsulation,inheritance, and polymorphism capabilities of Object-Oriented Programming (OOP) whichdemonstrates a great advantage of the Object-Oriented Programming (OOP) approach.Copyrights reserved.
    • Olumide Bola holds a bachelors degree of the University of Ibadan, Nigeria and is currentlypursuing chartered membership of the Computer Professionals Registration Council of Nigeria(CPN). He is also a member of Nigeria Computer Society (NCS). He has trained scores of peoplefor well over a decade in programming and non-programming courses. He is currently a SoftwareDeveloper and the Managing Director/CEO of Victolay Technologies Limited.Article Source:http://EzineArticles.com/?expert=Olumide_Bola==== ====A Fresh Web Design programmers specialize in custom, dynamic, interactive websites for mid-sized and small businesses.http://www.afreshwebdesignstlouis.com/services.html?category=2==== ====