maexus Posted March 7, 2008 Share Posted March 7, 2008 I've been writing PHP for about 6 years now and just started to dig into the subject of OOP this week. Didn't see a huge need for it until now. Now that I have been playing with it and really falling in love with the workflow it offers, I found myself wanting to do something but didn't know how. You would have a parent class. This is the object that you call in the code. You would then have children classes. They communicate with the parent and perform taskes only for that parent class. They would also be able to pass data to/from their siblings seamlessly. This just makes more sense to me when it comes to structuring my logic and degating responsiblities in the code. Is there a way to do this or atleast emulate it cleanly. Quote Link to comment Share on other sites More sharing options...
deadonarrival Posted March 7, 2008 Share Posted March 7, 2008 To do it, no - a child can use a parent's methods (using $this->parentsmethod(); or parent::method(), but not (so far as I know) those of a child - and only if you use the child to extend the class. I think it could be emulated, but it would be a workaround - you'd have to have an array in the parent containing the names of the children or something similar, and pass the names of the parent/sibling classes to the constructor of each class. I wouldn't like to be the one programming it. The hardest thing for people used to procedural PHP is, in my opinion, working out how to link the classes and use them with one another. Me among them. I'm currently working on the "Simplify, man" method. Break things down more and more, then call the smaller functions from a good ol' procedural script (usually a short switch statement) - meaning I never call another class from one class unless it genuinly does extend that class. Eg an admin extends a user, but neither an admin or user actually extend a database (although they execute static functions of an error) You have to go a bit insane and talk about your objects as people. Like the sentence above, think about them - as the name suggests - as OBJECTS. Literally. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.