|
Nnamdi Onyeyiri wrote:
what do you mean
Havent seen many posts from you lately, was just wondering?
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
Are there any good articles that anyone is aware of that explains in detail specifically what interfaces are and how they are used in C#. Thanks.
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
|
Thanks Paul,
A little further down in that discussion John Burton makes a comment [^] about them which makes me think they are used to describe a virtual function as we do in C++. However with your[^] comment they appear to implement the flavor of inheritance to a class. Both of which make some sense, however I would really like to read a full article where they are described in great detail. Thanks for the link though.
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
The problem is that C# is new enough that it is all a matter of opinion. To offer a single article (which I don't have, or I would do anyway) would be to offer only one person's opinion.
To my mind, neither viewpoint that you've picked out is strictly wrong, nor are they mutually exclusive. An interface is sort of like an abstract class for a language that otherwise doesn't allow multiple inheritance. So in a way, it is like offering a set of virtual functions.
The most useful purpose of this is to offer a flavour of inheritance to the class.
Does that make sense? (it is Friday night!)
Paul
|
|
|
|
|
Paul Riley wrote:
(it is Friday night!)
Don't tell me you shut down on Friday night....I get it, however just because C# is a new language doesn't mean there isn't anything more than someones opinion
As soon as I find out more about them I may just have to put together a little or big article than can clear this all up for us.
Go enjoy your Friday night, not too much though, otherwise Saturday will hurt you.
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
Good news, I found a really good article[^] that pretty much clears it up for me, take a look.
Nick Parker
The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown
|
|
|
|
|
That is a good article, well found.
I do think it could be better though . What an interfaces article needs is a single practical example: this is an interface, these are two classes that might implement this interface. What this does is say: this is an interface, and this is how you use one that already exists, proving how difficult it is to find a practical use for interfaces (the StringList example is pointless).
Just thinking aloud. I might be tempted to work on this when my workload calms down over the next few weeks and I get to finish the one I'm already working on.
Paul
|
|
|
|
|
I'm using interfaces on a project right now in a very practical way. I have a database that has 80 some odd tables in it tracking all kinds of entities that are used in reporting.
I have an interface:
public interface ISummarizable{
XmlDocument getSummaryXML();
DataSet getSummaryDataSet();
//... other methods
}
It allows me to write methods like this:
public void printSummary(ISummarizable it){
XmlDocument doc = it.getSummaryXML();
//... print doc
}
But I can apply that to any items in the database - customers, loans, collections, stores...
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Excellent example, afronaut! Feel like writing an article?
By the way, can I ask [slightly off topic] - why did you choose to use get... methods, rather than read only properties?
eg
public interface ISummarizable {
XMLDocument SummaryXML { get; }
DataSet SummaryDataSet { get; }
} Or was this just an arbitrary decision?
Paul
|
|
|
|
|
Paul Riley wrote:
By the way, can I ask [slightly off topic] - why did you choose to use get... methods, rather than read only properties?
Now for then even MORE off topic answer.
If a property has a ReadOnlyAttribute, the property will only be readonly to the designer, but it is still settable programatically, where only defining only a get property is never settable (pretty obvious)
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
That's not an answer... at least not to the question I asked
When I said "read only", I didn't mean "ReadOnly", I meant "get but not set". Then it's not available in the designer or the program (actually, it can still be visible in the designer but greyed out).
Paul
|
|
|
|
|
I think it's just that old java habits die hard.
Also, returning objects gives me a little more ease in passing them to additional methods.
As far as writing an article, great idea! I may have to lock myself in the labratory for a few hours tonight.
Best regards,
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Is there a class builder wizard in Visual Studio.NET? If not, is there another free/cheap one available?
Thanks much
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
I started working on one, but phew it's gonna take some time still....
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
leppie wrote:
I started working on one, but phew it's gonna take some time still....
Open Source it already!
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
I pocket a class in a dll.And the class implement a interface.
and then I load the dll with these code:
Assembly a = Assembly.Load("mydll");
Type t = a.GetType("mydll.myClass");
object obj = Activator.CreateInstance(t);
MyInterface Imyclass=(MyInterface)obj;//this line will cause runtime error;
The biggest problem is that when I use it as below,it can work.
import the dll to my project first.
MyInterface Imyclass=new myClass();
What is the problem??? Anyone can help???
lost my way
|
|
|
|
|
fftongzhi wrote:
Type t = a.GetType("mydll.myClass");
object obj = Activator.CreateInstance(t);
Type t2 = a.GetType("mydll.myClass");
Type t = t2.GetInterface("MyInterface");
MyInterface obj = (MyInterface) Activator.CreateInstance(t);
Does that work?
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
Are you fun me???Interface can not be create a instance.
Type t = t2.GetInterface("MyInterface");
MyInterface obj = (MyInterface) Activator.CreateInstance(t);
Absolutely these codes will make a exception;
Can you make a test before makeing your answer?
lost my way
|
|
|
|
|
fftongzhi wrote:
Type t = t2.GetInterface("MyInterface");
Oops, was pasting from my rusty brain
Type t = a.GetType("mydll.myClass");
//do some test here to make sure class has interface
MyInterface obj = (MyInterface) Activator.CreateInstance(t);
To be honest, I think the problem is as Eric described it. Define your inferface in another assembly, compile once and leave it
Give them a chance! Do it for the kittens, dear God, the kittens!
As seen on MS File Transfer: Please enter an integer between 1 and 2.
|
|
|
|
|
Apologize for my discourteous words.
I can get the interface in myclass.
let's try again. ( ( ( (
lost my way
|
|
|
|
|
Is the interface compiled along with the assembly that you load? Interfaces have assembly identity, so both the assembly you'll load and the loader need to reference the interface in the same assembly.
There can also be version number issues. If the interface gets recompiled after you've built mydll, the versions won't match.
|
|
|
|
|
Thank you first,but the problem is still here.
I think it doesn't matter with the version.
I made a test like this.
First I build a interface(Imyclass) in a Imyclass.dll;
Reference it in the project of myclass which implemented the Imyclass and build a myclass.dll
And then,reference the Imyclass.dll to the project want to load myclass.dll at runtime.
and these codes will still create a exception(specified cast is not void);
Imyclass ImyCls =(Imyclass)Activator.CreateInstance(t);
In this case,the version of Imyclass.dll will same in each project,and the problem is still going on.
Some thing special is ,in myclass,I used some struct defined by myself for fuction parameters and return value.Is that the problem of system defult serialization???
lost my way
|
|
|
|
|
very lucky,it works.
the problem is I use the interface dll in diffirent version.
Becouse I made a cope of the dll for load,when I update one I missed the other one.hehe............
lost my way
|
|
|
|
|
Is there any tutorials about ADO.NET in C# somewhere that you might know?
I want to learn how to add, remove and update an Access database.
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|