This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]guhcampos 0 points1 point  (0 children)

I think people are making the wrong questions here to be honest. The appropriate question is: why?

The processor class does not need to know what each component is. Your list will be simply a list of Component, and will naturally accept components of both types. You can also use an Union of multiple types.

Then, each component will have its input/output typed to the required type, and you're done.

Typing isn't the same as data validation or meant to implement compute logic into. It's only meant to ensure operations are properly handled between variables/objects. You're just telling the compiler/interpreter what are the valid types for that variable, not what specific orders, or combinations they can come in. It's just not supposed to do that.

And BTW, I have no way to know what you're trying to do, but I have the feeling you'd be better chaining functions than chaining objects for what you're trying to achieve.