1

I am trying to understand what Configuration Object pattern is. For instance in php, how to write the following class using Configuration Object pattern?

class User extends People {
    public function __construct($name , $email){}
}
1

1 Answer 1

2

Like this:

class User extends People {
    private $name;
    private $email;

    public function __construct($conf){
        $this->name = $conf->name;
        $this->email = $conf->email;
    }
}

Of course this pattern is for much more complicated situations, when you want to configure DB connection or some API client or smth like that. This pattern is helpful, when you need pass many properties or do some actions with them.

I think here's good article about this pattern: https://code.tutsplus.com/tutorials/whats-a-configuration-object-and-why-bother-using-it--active-11580

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.