Tight Coupling / OOP Question
Posted: Tue Jun 03, 2008 4:32 pm
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:
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!
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. */
}
}
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!