JimboJones Posted December 23, 2010 Share Posted December 23, 2010 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. 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? Quote Link to comment https://forums.phpfreaks.com/topic/222475-help-with-a-simple-oop-pattern/ Share on other sites More sharing options...
shlumph Posted December 23, 2010 Share Posted December 23, 2010 Does "Plugins" and "Database" both extend off of "Core"? Quote Link to comment https://forums.phpfreaks.com/topic/222475-help-with-a-simple-oop-pattern/#findComment-1150801 Share on other sites More sharing options...
KevinM1 Posted December 23, 2010 Share Posted December 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/222475-help-with-a-simple-oop-pattern/#findComment-1150855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.