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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.