Tight Coupling / OOP Question

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Tight Coupling / OOP Question

Post by nowaydown1 »

Greetings guys. I know there's a lot of expertise around in the OOP department. I haven't been at the OOP thing for very long, so I'm still learning. Let's say I have a class that looks like this:

Code: Select all

 
class Profile {
 
     private $name;
 
     public function load() {
          /* Let's pretend this actually uses the DB or something. */
          $this->name = "Something";
    }
 
     public function getComments() {
            /* Magical factory stuff here. */
     }
}
 
Assume that my getComments function is a factory method that returns an array of instantiated Comment objects. A profile might have a bunch of comments on it, so it seemed logical to me to have a method that resided within profile that would go and get me a collection of objects to work with.

What are you thoughts on the design of this? Is this tight coupling setup bad? Is there a pattern I should be looking at instead?

Thanks!
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Tight Coupling / OOP Question

Post by Maugrim_The_Reaper »

Seems fine to me, as a Model. The interesting part is how you make Profile aware of Comment in the first place - that's usually where bits of coupling creep in.
Post Reply