livethedead Posted May 29, 2012 Share Posted May 29, 2012 Alright so I've been looking through some OOP and I have a few questions regarding principles that are somewhat still foggy for me. In an abstract class should all properties and methods be static? Is it acceptable for example to have a private property with a static getter method? I'll probably be adding more to this thread as I'm trying to do some applying of my knowledge. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/263331-few-questions-reguarding-oop/ Share on other sites More sharing options...
scootstah Posted May 29, 2012 Share Posted May 29, 2012 Not necessarily. An abstract class simply defines the "structure" of the class for child classes that extend it. You can use static methods, private methods, public methods - it doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/263331-few-questions-reguarding-oop/#findComment-1349533 Share on other sites More sharing options...
shlumph Posted May 29, 2012 Share Posted May 29, 2012 The only time I ever create static variables/functions is when I want to set defaults for a class. At least, that's what I aim for. So later on, if I initialize the class and don't inject anything, the defaults will be used. Something like: <?php //Assume Table extends Database class Table extends AbstractDatabase{} //When bootstrapping the application $pdo = bla bla AbstractDatabase::setDefaultAdapter($pdo); //Later on, in a different section of the app $table = new Table(); //Uses default adapter $newPdo = bla bla bla $table = new Table($newPdo); //Uses the injected PDO Quote Link to comment https://forums.phpfreaks.com/topic/263331-few-questions-reguarding-oop/#findComment-1349540 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.