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?
Comments
Be the first to write a comment
You must me logged in to write a comment.