Jump to content

Help with a Simple OOP Pattern


JimboJones

Recommended Posts

I'm an experienced procedural programmer but trying to write my first pure OOP application and I know I'm not planning this right.

 

OVERVIEW:

Basically there are two parts to this application, an admin and a public side.

 

oop.gif

 

Admin contains administrative related methods, public is the same and both extend the core class.  Core contains shared code between Admin and Public and the four classes at the top perform their named functions.  Core includes those four classes and instantiates them as protected variables so that they're accessible by Public and Admin.

 

PROBLEM:

 

I can't figure out how to solve the following problems while staying true to OOP programming:

 

If "Plugins" needs to use a method in the "Database" class, how do I access it without reinstantiating it or calling it statically?  Right now when Core instantiates those classes and assigns them to a protected variable, I'm passing each one references to the other classes like so:

 

Core.php

$this->db = Database();
$this->fields = Fields(Database $this->db);
$this->plugins = Plugins(Database $this->db, Fields $this->fields);

 

But this is just nasty.  Based on the image and my description could someone offer their own suggestions on the correct way to pattern this application?

Link to comment
https://forums.phpfreaks.com/topic/222475-help-with-a-simple-oop-pattern/
Share on other sites

IMO, you need to scrap your design and start looking into the reasoning behind OOP as a methodology and various OOP design patterns.  Look into composition, abstraction, encapsulation, and polymorphism.  Also, for the web, the MVC pattern is essentially the de facto architectural pattern for medium to large sites.  Look at frameworks like Zend and Kohana to see how their application flow is designed.  That should give you a good idea on how to proceed.

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.