Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overload constructors #9

Open
SamMousa opened this issue Mar 29, 2016 · 1 comment
Open

Don't overload constructors #9

SamMousa opened this issue Mar 29, 2016 · 1 comment

Comments

@SamMousa
Copy link
Contributor

I think objects should have 1 constructor that contains all parameters.
If needed we can then create static factory methods to instantiate from specific parameters. These static factory methods are short hands that enforce the implicit demands on constructor parameters.
In the example below, $b and $rf for example are mutually exclusive.
The constructor must check this in code, but for a user of the library createFromAB abstracts from that requirement (by hiding $rf)

For example:

class Ellipsoid extends {

    public function __construct($a, $b = null, $rf = null, $code = null, $name = null) {

    }

    static public function createFromAB($a, $b) {

    }

    static public function createFromARF($a, $rf) {

    }

}

@judgej
Copy link
Owner

judgej commented Mar 29, 2016

Okay, I'd go with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants