Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Don't judge a man by his look. Don't judge a book by its cover. :D
  • Leaders
Posted

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. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Leaders
Posted

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}.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...