Skip to content

Don't overload constructors #9

@SamMousa

Description

@SamMousa

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) {

    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions