开发者

Is it ok to call a Registry Pattern object inside of the objects that make up the Registry?

I have asked a few question lately about the use of the singleton and registry patterns but here is a new question I have.

Let's say I have 3 main class object in PHP that I need to have access to inside 20 other class files and sitewide.

  • Database object
  • Cache object
  • Core object

I then can use a Registry pattern to store all 3 of these object into 1 registry object which we will call the "Registry object"

The registry class will have a singleton method so that we can make sure we only call the Registry object 1 time.

So far all is good, here is where I need your advice. All the 20 other classes now have access to the 3 main objects I mention above. But inside those 3 object above, is it ok to have them include the registry object too? Because they will ne开发者_开发技巧ed access to each other as well, or should I just reference a singleton method for the database, cache, and core object inside of each of these 3? This may be a dumb question and I am probably just a little confused because the singleton from the registry object probably makes it ok to include the reistry inside the objects that make up the registry?


Why don't you just make these 3 classes static? I'm using a static database class that kind of extends PHP's PDO class and let me use it like this:

$sql = "SELECT * FROM table";
foreach(DB::query($sql) as $row) {
  // do something
}

I really like this way of using static classes/functions especially for this "global" kind of stuff. Perhaps this is an option for you too?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜