Anton
Anton
CC#
Created by on 11/20/2024 in #help
overriding methods
tbh never done this tagging by subtyping. I usually reach out for a manually written tagged union. But I don't think it's bad necessarily
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
and those are the ones you have to implement
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
with an enum it's clear that those are the only allowed options
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
It's just open what all the subtypes are
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
you can do pattern matching over hierarchies too, to be fair
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
yes
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
you'll know it when you'll need polymorphism
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
yeah, and then a switch over this to determine what action to take
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
Less indirection means easier to debug and usually easier to understand
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
Especially for simple programs, this is a good idea
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
Unless you actually need polymorphism for some purpose, you're better off simulating the type of person yourself with an enum
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
it'd just jump to the right instruction from the start
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
when it's not virtual, or the compiler can determine at compile time (statically) which method will be called, at runtime none of this will happen
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
then it calls the method indirectly via the function pointer stored along in that entry
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
when you call a virtual method indirectly (through the base class for example, or through the child when the child class is not sealed) the CLR walks through that list at runtime to find the entry for the base type (the one which defines the virtual method)
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
that object in memory has a list where it stores the function pointers to the method implementations of the interfaces or the base class it implements
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
every class has this
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
it points at another object in memory specific to the type of that class
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
it has a hidden type info pointer field
90 replies
CC#
Created by on 11/20/2024 in #help
overriding methods
it doesn't have to be in a field
90 replies