PHP
  Home arrow PHP arrow Object Interaction in PHP: Introductio...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Object Interaction in PHP: Introduction to Composition
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2005-07-11

    Table of Contents:
  • Object Interaction in PHP: Introduction to Composition
  • Composition: some theory ahead
  • Composition in a practical sense: a basic example
  • The “Table” class: a simple row-color alternator
  • Working with the classes: a quick example

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Object Interaction in PHP: Introduction to Composition


    (Page 1 of 5 )

    Composition is an important concept in PHP. It occurs when an object creates another object; that is, the first object completely possesses the second object. In this article (the first of two parts), Alejandro Gervasio explains composition, and shows some examples to illustrate his points.

    Introduction

    From a PHP programmer’s point of view, there are many interesting ways that objects can interact with each other within an application. Used extensively across well-structured projects, inheritance is one of the major foundations of the object-oriented paradigm. It allows a  basic and generic functionality to be implemented on a base class, and provide generic methods and properties that are inherited by any derived subclass, in order to “fine-tune” the child classes to suit more specific purposes. If you’ve been working for a while with database abstraction classes, to cite an illustrative example, probably you know what I’m talking about here.

    Aside from inheritance, and its partner, polymorphism, we can find other situations where objects are involved in some kind of interaction. Definitely, one concept that rapidly comes to my mind is that of aggregation. If you’re unaware of its existence, you’re missing something really relevant, trust me.

    Generally speaking, aggregation occurs when one object uses the functionality of another object to satisfy its own purposes. Although this sounds a bit egotistical, the truth is that aggregation is an extremely powerful concept, used very frequently in object-oriented environments. Commonly, there are situations where one object, such as a database result set processor, needs to have database connectivity within its scope. This is a common case where this last object performs a query against a database, using the connectivity given by the first object, which is usually passed to the second as a constructor parameter.

    Definitely, this might sound familiar to you, if you work with objects in PHP on a daily basis. However, the subject is really very far from being fully covered. I hope you're wondering why. What about having an object that creates another object, that is, the first object completely possesses the second? Yes! Now we are talking about a concept often known as composition.

    So, do we have yet another big player in the OOP arena? You bet. What’s more, composition plays a very important role in many situations, where the interaction between objects is carried out in a carefully planned way. Thus, the subject deserves an indepth examination. That’s what I’ll do in the course of this article. I’ll offer a short introduction to the theory of composition, as well as its possible implementation in different practical situations. I guess that you’re ready to learn more about it, right? Okay then, let’s not waste any more time in preliminaries.

    More PHP Articles
    More By Alejandro Gervasio


       · The first part of the series explains the core concepts about object composition in...
       · Hello, Alejandro! You've heard it all before, but first of all I'd like to express...
       · I find myself in a position to be doing what everyone says you shouldn't: Learning a...
       · Hey, what can I say about the kind words you say about me? Thanks a lot for that! ...
       · hi there. there is one syntactic form that i can't really understand: $this-> object...
       · Hey Luis,Thanks for the comments on my PHP article. Concerning your question,...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT