dragon4spy Posted March 1, 2004 Posted March 1, 2004 Hi everyone! :) Could you tell me the differences between Structure, Interface, Delegate, and Class? It seems that these things are now (vb.net) capable to handle methods and functions as well. Is there any more objects that similar to Class?:D Quote Don't judge a man by his look. Don't judge a book by its cover. :D
Leaders Iceplug Posted March 1, 2004 Leaders Posted March 1, 2004 A Structure is much like the Type in VB6... you don't really have to instantiate it before you use it... you can in .NET, and you can also have Methods (Functions and Subs) within the class, also Shared methods and good stuff like that... it does pretty much what a class would do except the object-oriented stuff like Inheritance, Implementation, etc. :cool: An Interface is something that you add into a class... within the class, you can implement them to have some functionality... An interface is kind of like a plug-in socket to some device... you specify what the socket looks like (a 3-pronged wall socket has a source power, a source ground, and a body ground... those are what would be in the interface)... when implemented in the class, you get to do stuff with the source power, source ground, and body ground. :eek: In the Interface all of the subs and functions are just declared... nothing is added. A Delegate is like an Event Handler... well, it is an event handler. You can declare a delegate like this: Public Delegate Sub MvPtclListExitEventHandler(ByVal sender As Object, ByVal e As MvPtclListExitEventArgs) This is moving particle list exit event handler. So, in a class, I have moving particles which all must lie within some rectangle ... I instruct them to move in MoveSubroutine()... then I check the particle location... if they have moved outside of the rectangle, then I can raise the event handler: Public Event OutOfBounds As MvPtclListExitEventHandler which is declared at the declarations part of my class. When I RaiseEvent OutOfBounds(Me, mpleeargs), the delegate "gets in the car and drives", looking for places where it can be handled in the project. So, I happen to be handling it in an event on a form Private Sub Swarm_OutOfBounds(ByVal sender As Object, ByVal e As MvPtclListExitEventArgs) Handles Swarm.OutOfBounds The delegate "pulls into the driveway", drops the arguments (Me, mpleeargs) from the class... and then the event runs. :D Also, MvPtclListExitEventArgs is a class which Inherits System.EventArgs and you can add methods and properties to it. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
dragon4spy Posted March 1, 2004 Author Posted March 1, 2004 Is it simple? But why interface is used then? Is it just a skeleton? Quote Don't judge a man by his look. Don't judge a book by its cover. :D
Administrators PlausiblyDamp Posted March 1, 2004 Administrators Posted March 1, 2004 Interfaces allow a framework to provide placeholders / plug in mechanism when the framework knows what functionality is required but not how a given class needs to implement it. e.g. Have a look at Array.Sort and the IComparable interface. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
dragon4spy Posted March 1, 2004 Author Posted March 1, 2004 Would you mind givin' a demostration? Quote Don't judge a man by his look. Don't judge a book by its cover. :D
*Gurus* divil Posted March 1, 2004 *Gurus* Posted March 1, 2004 Is there something wrong with the detailed explanations on these topics that MSDN gives you? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Leaders Iceplug Posted March 1, 2004 Leaders Posted March 1, 2004 You can simply search for something like IComparable or IFormatter with the Documentation Help Search. For instance, assume I have a vector class that implements IFormattable. IFormattable provides you with an empty ToString() function for your class. Sure, you can just call it directly MyVector.ToString() but, you can also use it here: Console.WriteLine("My vector is {0}.", MyVector) and it will call my .ToString() property of My vector to determine what to put in place of the {0}. Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.