4 ms·
Rebuttal, how do you implement interfaces in OOP languages in cases where you don't yet expect the object to exist, e.g. an interface with toString and fromStri
by mrkeen 2y ago
Rebuttal, how do you implement interfaces in OOP languages in cases where you don't yet expect the object to exist, e.g. an interface with toString and fromString methods.
- caspper69 2y agoWith the interface keyword (java/c#). You just define the required methods and that's the interface.
- layer8 2y agoThink again about fromString, that would be a static constructor method. The GP is looking at metaclasses.
- caspper69 2y agoI'm not going to attempt to speak for java, but at least in C#, it supports virtual static methods in interfaces, including generics. So, as I stated, you would use the interface keyword. public interface IFromString<T> { static abstract T FromString(string value); } public struct MyHasFromString : IFromString<MyHasFromString> { public string Text = ""; public MyHasFromString(string value) { Text = value; } public static MyHasFromString FromString(string value) => return new MyHasFromString(value); public override string ToString() => Text; }
- deleted 2y ago[deleted]