Jump to content

class design question


RShadow

Recommended Posts

I need a little assistance in designing a few classes.. what I want to be able to do is create a class that will be used through out my code, but a different back end.  For example

I would like to create say an interface class that defines a number of methods that classes will implement... but I don't wan't to use the implemented classes in my code.. I want to use the interface class, and have the interface class decide what implementation to use.. any ideas on how to accomplish this?
Link to comment
Share on other sites

I don't know if the is the "correct" way but if you don't define each method in the subclasses you get error

[code]<?php
abstract class test2 {
abstract function foo1 ();
abstract function foo2 ();
}

class test2_1 extends test2 {
function foo1() {
echo 'foo1_1', '<br/>';
}
function foo2() {
echo 'foo2_1', '<br/>';
}


class test2_2 extends test2 {
function foo1() {
echo 'foo1_2', '<br/>';
}

// remove # from next 3 lines to get rid of error

# function foo2 (){
# echo 'foo2_2', '<br/>';
# }
}

$x = new test2_2;

$x->foo1();
?>[/code]
Link to comment
Share on other sites

I undstand that, but I'm trying to do is never directly call test2_2, but have all my code call and use test2 and have test2 decide (based upon some set variable) which implementation to use (be it test2_2 or test2_3, etc).
Link to comment
Share on other sites

That's what I was figuring, so I knew it was impossible to make this design by a child parent relationship... what I'm going to have to do is create some sort of middle man or go between class that will manage the connection.  Proably what I'm going to do is create a class that physicaly enumate a certain directory on the server and look for "modules" and then if a global variable is set to use one of those modules it will (include) that module, otherwise include a default module... I was just hoping that perhaps there was a more elegant way to accomplish this.
Link to comment
Share on other sites

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.