Make static factory methods possible. #8243
Unanswered
procodix
asked this question in
Language Ideas
Replies: 3 comments 12 replies
-
You may be able to accomplish this by a source generator. |
Beta Was this translation helpful? Give feedback.
3 replies
-
See: #5413 |
Beta Was this translation helpful? Give feedback.
8 replies
-
What happens if your derived class Animal(int numOfLegs) {
public static Animal Factory(int numOfLegs) => new Animal(numOfLegs);
}
class Cat(Color furColor) : Animal(4); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
B::Factory() returns an A not a B, which is a violation of inheritance.
There should be a new keyword like "This". During compilation all static methods with this keyword have to be copied for all subtypes and "This" has to be replaced with the Copy's type. That saves the burden of manually copying the method into every class.
Beta Was this translation helpful? Give feedback.
All reactions