Trying to learn about interfaces
Is the pseudocode shown in my image a practical use of interfaces?
15 Replies
yep, thats how interfaces work.
you don't need to specify
public
in the interface tho (for the method)
void SomeMethod();
will have the same effectinterface methods are public by default?
ye
sick, thank you
can you have members in interfaces?
you can have properties
ah ok
I don't think you can have fields.
I have never tried or wanted, in 20 years of coding C# 😄
and does the inheritor have to implement a body for the property?
fields shouldn't be visible outside of the class :3
for exactly this reason have I never tried
right
well, tehy have to implement the prop - so at minimum they need to specify an autoprop with the same name and type
so should you pretty much always use properties to expose fields outside of a class?
you can also specify in the interface
{ get; }
but in the implementing class also have a setter, thats fine
yesgot it
thank you, ive been using these concepts without really understanding them and this helps a lot