Page 1 of 1

Tight Coupling / OOP Question

Posted: Tue Jun 03, 2008 4:32 pm
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!

Re: Tight Coupling / OOP Question

Posted: Wed Jun 04, 2008 2:57 am
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.