Jump to content

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.

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.