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 Aggregation, part 1
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 22
    2005-05-25

    Table of Contents:
  • Object Interaction in PHP: Introduction to Aggregation, part 1
  • What is aggregation?
  • Applying aggregation in a practical manner: defining sample classes
  • A closer look at aggregation: the boosted "dataMailer" class
  • Aggregation in action: a concrete 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 Aggregation, part 1


    (Page 1 of 5 )

    Aggregation in PHP allows one object to use another object. It's a very powerful concept. This article, the first in the series, serves as an introduction to some of the things you can do with aggregation.

    Introduction

    In the growing world of Object Oriented Programming, the ways that objects interact with each other involve directly working with several concepts that deserve an in-depth look, in order to take advantage of their power in real-world applications. Particularly when we're dealing with PHP, which is definitely an easy-to-grasp language compared to the harder learning curves of Java or C++ (among others), things are a lot more accessible, even if we go beyond the limits of working with procedural solutions.

    At this point, most PHP users have already experienced the nice capabilities of PHP classes, by taking either the do-it-yourself road or reusing existing, well-trusted classes for managing larger projects. However, there are times where we need to work with several classes that require a strong interaction to efficiently accomplish a given set of tasks. So, this relationship immediately brings up a question: how do objects interact? Fortunately, the answer is quite straightforward, since this interaction can be defined within well-known OOP pillars.

    The first trusted friend is inheritance, which offers a powerful mechanism for building class hierarchies, and allows us to address specific issues in a number of subclasses without the need to recreate the logic or functionality that already exists in the super class or parent class. That sounds very familiar, doesn't it?

    The next big ally of inheritance is polymorphism, which is defined as the ability of different classes to behave differently for the same operation. In programming lingo, we can say that two or more classes are sharing the same interface. Probably its most common application is found within database abstraction classes, where we're using the same method (i.e. connect) for connecting to different databases systems.

    So, that's all there is to know about object interaction? Well, not yet. Aside from inheritance and polymorphism, there are a couple of interesting ways to make objects interact. Maybe you've been working with an object that uses another object, right? Or perhaps worked with an object that creates another one? Sure! We're referring to the concepts of aggregation and composition. These two additional forms of object interaction are extremely useful, giving us undoubtedly strong foundations for deeply exploiting the power of object-oriented programming.

    However, all of these things sound like a bunch of buzzwords, with no immediate use in Web applications, right? Well, not so fast. We have the power and need to use it. In this article, we'll introduce ourselves to the process of implementing aggregation in PHP, to help us learn  more about the possible ways to make object interaction work for us. Let's get started.

    More PHP Articles
    More By Alejandro Gervasio


       · This first part of the series introduces the concept of Aggregation in PHP in a...
       · Thanks for the article.What makes it less "abstract" is that its not about...
       · Thanks for your kind comments about the article. Having "suffered" of the side...
       · Very clear and easy to follow. Thanks much.I do, however, have a question that...
       · First off, thank you for your kind comments about the article.Now, your question...
       · an aggregate object has the benefit of being able to share events that would be...
       · Yes, your example is good. Generally speaking, one object aggregates another for the...
       · Great Article, very informative and written well, Thanks.I support advertisers of...
       · It really isn't too difficult to print out the article. If you look under the...
       · Thank you for the kind comments on my PHP article. Sorry to hear that you've having...
     

       

    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 3 hosted by Hostway
    Stay green...Green IT