Home arrow PHP arrow Page 2 - Object Interaction in PHP: Introduction to Aggregation, part 1

What is aggregation? - PHP

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.

TABLE OF CONTENTS:
  1. Object Interaction in PHP: Introduction to Aggregation, part 1
  2. What is aggregation?
  3. Applying aggregation in a practical manner: defining sample classes
  4. A closer look at aggregation: the boosted "dataMailer" class
  5. Aggregation in action: a concrete example
By: Alejandro Gervasio
Rating: starstarstarstarstar / 23
May 25, 2005

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

In the context of object interaction, aggregation simply refers to a situation where one object is passed to another object to perform some operations or methods within the object that called it originally. Usually, the second object is passed to the first one as a parameter using one of its member methods.

The great benefit of this is that, with the second object living happily in the first one, it's possible to directly call its methods, allowing us to take advantage of its existing functionality, in order to fit the purposes of the first object.

In terms of practical application, aggregation is extremely important and powerful. After all, if I consider myself as an object A, which has a rather limited budget, but fortunately has a rich friend, that is, an object B, who is generously offering to me (at least temporarily) his credit cards, that is $B->offerCreditCards(), to buy that NAD state-of-the-art preamplifier, I'd feel very powerful!

If we talk about performance issues, the advantages of aggregation mainly come from its lower overload, since most of the time only one object is shared by other objects. However, this advantage might be discarded in the case of having a class for database connection shared by other multiple classes. You may run into difficulties if multiple database connections are established to the same server, causing a noticeable detriment to the system, particularly if your site is attracting many visitors.

Are you feeling as if it's a bit confusing to handle objects here and there? It's best to understand this by example. In the next section, we'll define two simple classes to illustrate the concept of aggregation in a practical sense.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: