❔ Why can i not override a Method from a class that extend a Interface
Here i try to override the Method "Initialize" but it does not work, is there a way to override it?
87 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i want it optional
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
to override
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
toolset?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
dev told me its right to use it like that if i want it optional
but yea i can remove the public
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
If it's optional to provide it shouldn't be in the interface
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
what should i use then?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
but it is a register system
so i not need everytime Draw method
but when i need it i can just override it
and it get called
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
then i need to implement all methods
what if i just need 1
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Here i try to override the Method "Initialize" but it does not work, is there a way to override it?What does this mean?
but then i can not call it like:
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
^^ then would it not auto cast to the right type
... i need everytime to cast it
What do you mean when you say it does not work?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
You said "it does not work"
not if it in a interface
What do you mean by that
Do you get an error?
Do you not see the thing that you expected to be called called?
no i can not override the interface methods
when i before use a class that extend from it
What do you mean by that???????
what?
When you say you can't override interface methods?
Why do you say that? What observable output are you basing this on?
look
c# does can not handle the interface method
if i do ClientFontRegistry : Registry : IRegistry
Registry does brake it...
I am trying to help you out here, but just saying "it does not work" without actually saying what is not working is not helping me here
wtf
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
no error message
it just not work
Ok... then what is happening
it not allow me to override the methods from my interface
I do not believe you that this code has no error messages 🙂
because i before use Registry to extend from it
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
This is not the code I replied to
yea if i use override yes
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Alright. So, after pulling a bunch of teeth here, let me see if I have this right. Code that effectively looks like this:
You expected to print
ClientFontRegistry
, but actually printed IRegistry
Is that correct?yes
i mean yea Registry does brake it
Ok. Reimplement
IRegistry
on ClientFontRegistry
What is happening here is that Registry
needs to implement IRegistry
, and IRegistry
provides a default. So that's it. No more virtual dispatch occursyep now would it work but i wanna use the methods of Registry too
ouf
You could reabstract
Initialize
in Registry
if you wanted as wellyea...
And force inheritors of
Registry
to provide a non-default implementationmaybe is a static method then better from Registry
or wait
is it possible to extend from 2 things?
like 1 interface
Extend? No
and one normal class
like java
😄
You can implement multiple interfaces
But you can only have 1 base class
oh
so that works
thxx
you helped me
It does, but it also possibly doesn't
rider tells me that it get called
so im sure it works
let me try it
yepp
thxxx for our help
If
Registry
overrode functionality, you'll lose it
thats why i not call it anymore from it
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
that would work too
but i think that way i has now is better
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
But thx for our help!
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
im more fan of this, it looks way cleaner
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
oh ok
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
$tias
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Orannis#3333
You can implement multiple interfaces
Quoted by
<@!689473681302224947> from #Why can i not override a Method from a class that extend a Interface (click here)
React with ❌ to remove this embed.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
i call it like that...
that would just ignore this methods
because
i get the right type
but c# still use the default classes
Why does
Registry
implement IRegistry
?
I think what is happening is that ClientFontRegistry
inherits from Registry
, Registry
implements IRegistry
, so when you try to implement the methods from IRegistry
on FontClientRegistry
then it just ignores those since the interface is already implemented in the base class.I'm seeing a bit of a violation here against the interface seggregation principle. Do not depend on interfaces you don't need. Your have two types that each use this interface but none of them fully uses it. What you've done is essentially you have created an interface which should partially be implemented by
Registry
and partially implemented by ClientFontRegistry
. Just make two smaller interfaces having one get implemented by Registry
and one get implemented by ClientFontRegistry
.Remember to $close when the question has been answered 🙂
Use the
/close
command to mark a forum thread as answeredWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.