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

Use new static when creating new instances of Uri #39

Closed
wants to merge 1 commit into from
Closed

Use new static when creating new instances of Uri #39

wants to merge 1 commit into from

Conversation

rbayliss
Copy link

Currently, it's impossible to extend the Uri class, since it creates new instances of self, instead of static. This behavior is also inconsistent, since in other places it does a clone, which will create a new instance of the extending class. This PR just changes the instance creation logic to always use new static.

@mtdowling
Copy link
Member

These changes make the assumption that subclasses all use the same constructor signature; however, subclasses might override the constructor with a different signature. Because constructors are not required to follow the Liskov substitution principle (LSP), this is a concern and the reason I did not use static initially.

This behavior is also inconsistent, since in other places it does a clone, which will create a new instance of the extending class.

When using a clone, the constructor is not invoked -- only the __clone method. We do not use clone in the Uri class because the static methods you reference are used as factory methods (e.g., "named constructors") for the concrete Uri class.

@rbayliss
Copy link
Author

Got it. Thanks for the clarification.

@rbayliss rbayliss closed this Sep 22, 2015
@rbayliss rbayliss deleted the extendable_uri branch February 11, 2016 01:30
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

Successfully merging this pull request may close these issues.

None yet

2 participants