Jump to content

Few Questions Reguarding OOP


livethedead

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/263331-few-questions-reguarding-oop/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.