Sei sulla pagina 1di 4

C

l
a
s
s
i
f The Object-oriented-ness of PHP
i
c
a
t
i
o Introduction
n In this paper, I am discussing about the object oriented-ness of PHP. PHP is a strong scripting language.
i Its mainly used for web-development. PHP stands for “Hypertext Preprocessor”. Early versions of
s PHP weren't object oriented. Object Oriented feature was added to PHP 5. It was released in 2004.
t In the next section we will understand what exactly means to be object oriented programming.
h
e
What is Object & Object Oriented Programming?
m Class is a template, which consist of data & methods that operate on that data. Object is an instance of a
e
a class. The core concepts of object oriented programming are: Identity, Classification, Generalization,
n Specialization, Abstraction, Polymorphism, Inheritance, Enapsulation, Information Hiding,
s
Modularization and Access Modification. We will discuss these concepts and
w
h
e Identity: All the objects are same in nature and behavior. An Identity uniquely identifies an object. ?
r
e
b
y Classification: Classification is the means whereby we order knowledge[11]. Classification means

w keeping similar objects together (in a class) & separating the objects which have different behavior.
e Classification helps in modularization of application.

o
r
<?php
d
class Car
e
{
r
protected $_wheel;
protected $_seat;
k
function assign_Values()
n
{
o $this->_wheel = 4;
w $this->_seat = 5;
l }
e }
d ?>
g
e
.
Generalization: Generalization is a relationship between a class and one or more refined version of
it[1].
Specialization:
Abstraction: It consist of focusing on the essential, inherent aspects of an entity and ignoring its
accidental properties[1]. Abstraction is the selective examination of certain aspects of a problem. The
goal of abstraction is to isolate those aspects that are unimportant.[1] A simple example in common
world would be a Television. The most common thing about Television that people knows is it runs on
electricity. So, people watch entertainment, but doesn't bother about how the images appear on TV or
how the signal is traveled from TV station to our house. Abstraction increases the ease to reuse the
object by hiding the details. So that the user doesn't waste time in understanding the details of an entity.

Abstraction is confused with interfaces.

Two types of abstraction: Data Abstraction and Process Abstraction.

(PHP website)
PHP 5 introduces abstract classes and methods. It is not allowed to create an instance of a class that has
been defined as abstract. Any class that contains at least one abstract method must also be abstract.
Methods defined as abstract simply declare the method's signature they cannot define the
implementation. When inheriting from an abstract class, all methods marked abstract in the parent's
class declaration must be defined by the child; additionally, these methods must be defined with the
same (or a less restricted) visibility. For example, if the abstract method is defined as protected, the
function implementation must be defined as either protected or public, but not private.

Information hiding

It is always confused with encapsulation. But, Information hiding and encapsulation have different
meaning.

Encapsulation
Access Modification:
PHP has three access modifiers:
Public (default) – can be accessed by any part of a script both inside and outside the class.
Protected – prevents external access to a property or method, but permits access internally and to parent
and child classes..
Private – can be accessed only within the class where they are defined.

Modularization: Modularization is a process of dividing a system into smaller modules.


Modularization It increases the flexibility, efficiency and understandability and robustness of the
system & reduces the scope of an error to a particular module. The effectiveness of modularization
depends on design decisions taken. Although, the unconventional criteria of modularization ensure
clean decomposition, it may prove inefficient in certain cases. So, it is very difficult to generalize a
criterion for modularization. Rather, it should be decided according to the structure of system being
modularized.

Polymorphism: PHP is weak typed language. So, it doesn't support typecasting. So, it can't support
polymorphism extensively.

Inheritance(Paper summary: A Survey of Object-Oriented Concepts):

Class inheritance provides a simple and powerful mechanism for defining new classes that inherit
properties from existing classes. Inheritance simplify large pieces of software & thus leads to
reusability.
Inheritance exposes a subclass to details of its parent's implementation. Therefore, it's often said that
'Inheritance breaks Encapsulation'. Many object-oriented languages allow free access to inherited
instance variables by descendant classes, thus denying the designer the freedom to compatibly change
the representation of a class without affecting methods.
So, it is encouraging that several newer languages must correct these deficiency by restricting access to
inherited instance variables.

PHP supports inheritance. An extended class is always dependent on a single base class, that is,
multiple inheritance is not supported. Many languages like C#, Java, Objective-C also doesn't support
multiple inheritance. Classes are extended using the keyword 'extends'.
Delegation

Conclusion:
PHP supports object oriented concepts. But, it still lacks to be called as a complete object oriented
language

References:

1. Object-Oriented Modeling Design: James Rumbaugh, Michael Blaha, William Premerlani,


Frederick Eddy, William Lorensen.
2. Abstraction, Encapsulation, and Information Hiding: Edward V. Berard.
3. Classical And Object Oriented Software Engineering: Stephen R. Schach
4. On the criteria to be used in decomposing Systems into Modules(Parnes, 1972)
5. A Survey of Object-Oriented Concepts
6. PHP Object-Oriented Solutions: David Powers.
7. Object Oriented Methods - A Foundation: James Martin, James J. Odell
8. Object-oriented PHP : concepts, techniques, and code: Peter Lavin
http://my.safaribooksonline.com/book/programming/php/1593270771/firstchapter#X2ludGVyb
mFsX0ZsYXNoUmVhZGVyP3htbGlkPTE1OTMyNzA3NzEvMTQ=
9. http://www.php.net/docs.php
// http://my.safaribooksonline.com/book/databases/mysql/9781590598627/firstchapter
10. http://lib.myilibrary.com/Open.aspx?id=167483&loc=&srch=undefined&src=0
11. Object-Oriented Analysis and design: Grady Booch

Potrebbero piacerti anche