Home Links
Home Page
Blocks try... catch... finally... in JScript 5.
Processing of events in language JavaScript
Job with Cookies on JavaScript
Processing of mistakes in PHP
Installation of the password on page
Erroneous methods of promotion of sites
Erroneous methods of promotion of sites
Keywords - the theory
Do not cling to searches!
Adjustment Firewall under ICQ
Adjustment Firewall under ICQ
Safety PHP+MYSQL+Apache
We use base MySQL
Creation of watermarks with help PHP
Twenty six ways of reception of the qualitative traffic on your site.
Unjustified use OOP
Simple way keshirovanija pages
PHP an example of parsing URL for « User Friendly URLs
 

Unjustified use OOP

Paradigm OOP - the remarkable approach to a spelling of a code. At OOP there is a set of conclusive advantages, most significant of which - an opportunity to use anew already once written code. However all of us sooner or later realize that fact, that ' PHP - not object-oriented language '.


In spite of the fact that PHP has correctly working support of objects, to use objects there where it is possible to do without them - short-sightedly and inefficiently. The reason? The matter is that support of paradigm OOP in PHP is realized not in full.


Despite of presence of basic elements, PHP all does not suffice many "advanced" functions (as the protected members or the closed variables) which are obligatory for the "present"{"true"} object-oriented languages (for example, Java, C ++).


Besides support of objects in PHP is insufficiently fulfilled and not so effective. It means, that use of paradigm OOP can lower speed of performance of the program essentially.



The note: In other words, the script working on objects will be executed more slowly, as a code inside eval () in comparison with a usual code. For more bright examples where use OOP accepts any ugly forms, it should to resort to the advanced functions to concepts PHP, some of which even nezadokumentirovany. So we shall stop on it.



And what we can without OOP?


If you came in PHP from Java or C ++ where without objects it is difficult to create something more or less serious and in PHP to you will be difficult for doing without they. But be sure, that serious applications can be written and techniques and receptions OOP (PHP last as we know has been written on C, and, does not support objects).


So, for those who has not got used to do without OOP, we shall result alternative technologies of a spelling of coherent and expanded applications outside of paradigm OOP:

Creation API.

Development of the concept imenovanija (and job in its{her} frameworks).

Grouping of the interconnected functions in one file.

Creation API


Let's correlate a code of the program with three levels:

The first - actually working functions.

The second - API functions. Functions for construction of the concrete application here enter.

The third - the application:



<? php

// MortgageRate.php (the Hypothecary Credit)


// A level the first - internal functions

// Internal functions for calculation of the optimum interest rate proceeding from time and the size of monthly payments


function _mort_find_interest_rate ($total) {

    if ($total <30000)

        return (7.4);

    elseif ($total> 30000)

        return (3.2);

    elseif ($total> 50000)

        return (2.5);

    else

        return (1.7);

}


// A level of the second - API functions


// double calculate_mortgage_rate (int money, int time, int month)

// Expects the interest rate proceeding from the sum of the loan, time of repayment and an interval of payments


function calculate_mortgage_rate ($money, $time, $month) {

    $rate = _mort_find_interest_rate ($money) / 100;

    $money / = ($time / $month);

    return ($rate * $money) + $money;

}


?>



<? php

// CalcMortgage.php


// The third level - the application

// $money, $time and $period it is received from the form


include_once 'MortgageRate.php';


$price = calculate_mortgage_rate ($money, $time, $period);


print " your interest rate for $period makes $price ";

?>



Development of the concept imenovanija and job in its{her} frameworks.


One of the most unpleasant moments by development of the big applications are conflicts of space of names. Classes of it  segment. Thus, different classes can:

To have properties with identical names or

To comprise methods with identical names.

For example, class Phillips and class Normal can simultaneously contain a method with a name screwdriver.


In general, before the beginning of the big project it is recommended to think over imenovanie for all, in particular, ways of distinction of global and regular variables, definitions of library functions, etc.

Grouping of the interconnected functions in one file


Connected API functions are the best way for collecting in one file the same as the connected methods are united in a class. Such files can be presented classes where each function represents as though a method of this class. So, each function will have clear definition and transparent structure.


For example, it would be possible all functions connected to dialogue with a DB, to collect in file DB.php.

OOP, as well as all on light, is good in a measure


The small clause: this chapter{head} has been written not to dissuade you from use OOP in general. More likely, it there was an attempt to convince you to not work with PHP in mode Java or C ++, where OOP - the decision number{room} one.


Lead{Carry out} the careful analysis of all benefits and losses before to apply the objective approach in PHP.