Greetings to all TypeScript enthusiasts!
Here's a challenge I want to tackle: I aim to establish an interface -- let's name it IShape -- and define several classes (Rectangle, Circle, Triangle) that adhere to the IShape interface.
Let's say that IShape includes a method called GetName which provides a string representing the shape's name. For now, let's assume that each class implementing GetName returns a static string (e.g.: "Rectangle", "Round object", "Pointed figure"). Additionally, let's envision that IShape incorporates the Draw method.
During runtime, my objective is to compile and display a list of all classes that implement IShape, thereby allowing users to select a shape from a drop-down menu. Upon selection, the system should invoke the selected shape's Draw method.
However, here's the twist: in the future, I wish to introduce new classes that conform to the IShape interface (let's call them Square and Oval). The next time I execute the code, these new classes should automatically appear in the drop-down menu without requiring extensive modifications to the existing code base.
How can this be achieved in TypeScript?
The ultimate goal is to create a flexible system that empowers team members to expand upon my code by introducing new shapes that adhere to the established interface, eliminating the need for a hardcoded list of accepted shapes.
I appreciate any assistance you can provide. Thank you.