Jump to content

Questions about OOP...


ShibSta

Recommended Posts

I've been coding PHP for some time and would consider myself to be at an intermediate level. I can write code to do what I need but it's probably not the best way to do it. I rarely see any code that I am not able to read, understand, or follow. I've created modifications for everything from vBulletin, WordPress, Kayako Support Suit, Magento, and more.

 

However, I've never really built a strong understanding around OOP. For example, let say you have the following classes:

_main

  -  db

  -  admin

  -  -  modules

  -  -  -  dashboard

 

How would you share the db connection with the dashboard class? I've been trying to read up on Dependency Injections and Singletons but I haven't found an article that has explained it on a level that I can understand. I get a feeling that most people who use OOP in PHP have a background in Java or C++ and are much more familiar with everything.

 

Could someone please explain this to me in simple terms or link me to an extremely well explained article that I'd be able to understand without a background in computer science?

Thanks

Link to comment
https://forums.phpfreaks.com/topic/213962-questions-about-oop/
Share on other sites

How would you share the db connection with the dashboard class?

 

Pretty much like you would share anything else: by passing it through the constructor or a setter-method.

 

public function setDatabaseAdapter(Zend_Db_Adapter_Abstract $adapter)

 

 

Link to comment
https://forums.phpfreaks.com/topic/213962-questions-about-oop/#findComment-1113587
Share on other sites

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.