Jump to content

Recommended Posts

HI everyone!

 

So basically I have this class called Login and another class classed Reports. They both extend a main class called OOP. I'm trying to get classes now and in the future, when I add on, to access that class so that way I dont have to create a new object everytime I need to do that. Plus I know I dont want to rely on calling another class inside of one class.

 

Here is an example

 

The Super Class

class OOP{
public function Login($pointer){
$Login->{$pointer}();
}

public function Reports($pointer){
$Reports->{$pointer}()
}
}

 

Login Class

class Login extends OOP{
public function userLogin($user, $pass){
//Login code here
//if error occurs, send it to Reports
super::Reports(Error());
}
}

 

Reports Class

class Reports extends OOP{
public function Error(){
//Send an error here
}
}

 

Here is how I think I would call the class if a user was to login.

$OOP = new OOP();

$OOP->Login(userLogin($user, $pass));

 

So now when I need to call any class I should be able to, correct?

 

 

If you are confused about the top, then think of it this way:

I am trying to create a class to where I can call or reference to ANY object now or in the future so I can add on and call that class from another class.

 

 

Thank you for any help.

 

This is pretty much the antithesis to good OOP.  The whole idea behind OOP is that objects are separate and don't know the internals of another object.  Having child objects work back up the chain to call a superobject's (whose very name should be a warning sign) method is completely ass backwards.

 

What you need to do is rename your OOP class to something better, and treat it as a Facade (it's a design pattern, google it)*.  Then, make the Login and Report classes not inherit from it.  The Facade's login method would delegate to the Login object and Report object as necessary.

 

*You likely don't even need a Facade, but it depends on the complexity of your system.

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.