0
I created these methods in the interface:
public interface IEvents
{
void OnEscrever(string text);
void OnEnable(bool b);
void OnDisable(bool b);
}
I’ll have some classes that will inherit these methods:
public class Herda1 : IEvents
{
public void OnDisable(bool b)
{
throw new NotImplementedException();
}
public void OnEnable(bool b)
{
throw new NotImplementedException();
}
public void OnEscrever(string text)
{
throw new NotImplementedException();
}
}
public class Herda2 : IEvents
{
public void OnDisable(bool b)
{
throw new NotImplementedException();
}
public void OnEnable(bool b)
{
throw new NotImplementedException();
}
public void OnEscrever(string text)
{
throw new NotImplementedException();
}
}
I want every method of the class Herda1
and Herda2
or other classes they inherit IEvents
, receive values per parameters.
Let’s imagine the component Timer
from Windows Form, it has its event called Timer1_Tick
by default, I cannot see how the script of this control unfolds internally, I can only pull the value through the method parameter, or by the instance.
What if I wanted to play that method on the interface? E All classes that inherit this interface, could receive by parameter values developed internally? And these methods were already delegated by default?
In java, I used (Implements Interface) to implement the methods. In C# I have no idea how to do it.
Just follow my lead:
I want when the interface methods are implemented automatically, to be delegates in any of the above green classes. Is that possible? If so, how?
Let’s suppose the very event of C#
public delegate void Disable(bool b);
public delegate void Enable(bool b);
public delegate void OnEscrever(string text);
public class ImplementaInterface : IEvents1 // efetua trabalho interno
{
public event Disable OnDisable;
public event Enable OnEnable;
public event OnEscrever OnEscrever;
public ImplementaInterface()
{
this.OnDisable += new Disable(??????????); // eis a questão
this.OnEnable += new Enable(??????????); // eis a questão
this.OnEscrever += new OnEscrever(??????????); // eis a questão
this.OnEnable(true);
this.OnDisable(true);
this.OnEscrever("Ola Mundo!");
}
}
public interface IEvents1 // qualquer classe pode herdar essa interface
{
event Disable OnDisable;
event Enable OnEnable;
event OnEscrever OnEscrever;
}
public class Herda1 : IEvents1 // esta classe esta herdando a interface
{
public event Disable OnDisable; // isso não é método delegado
public event Enable OnEnable;
public event OnEscrever OnEscrever;
}
public class Herda2 : IEvents1 // esta também está herdando
{
public event Disable OnDisable;
public event Enable OnEnable;
public event OnEscrever OnEscrever;
}
Notice that I put in the interface the operator event
, when some class instantiates this interface, it will not receive methods, but variable what I do not want. To understand, note the question comment, this is where I want to delegate the interface methods.
The code isn’t 100%, but that’s all I’m getting at.
Don’t I understand your doubt? a confusion only, in this case you implement interface in the classes is equal in C#.
– novic
I don’t know C#, but when I used to use an interface in Java, I got automatically delegated methods.
– sYsTeM
if you are talking about methods already implemented the approach is class
abstract
? that would be it.?– novic
Yes, too, but receive parameters and any class that inherit the interface, have methods already delegated without I need to delegate, because if I do this, will not fulfill the internal script work, but it is I who will do this work.
– sYsTeM
Put an example in your question, explaining the functionality, I’m wanting to understand where you’re going, I think (achometric) you need a class
abstract
with methods already implemented or inheritance in a base class ... !!!– novic
I left an example at the end of the/
– sYsTeM
You need to implement an independent method whatever it is, so in case it has to be a class
abstract
or even a base class making inheritance seeing from afar I think that’s it.– novic
Has as an example?
– sYsTeM
Check it out: https://www.codepile.net/pile/AzWqV1nJ but, I’m not sure that’s it.
– novic
Let’s go continue this discussion in chat.
– sYsTeM