I may be just stupid, but I don't understand the point of using an
Interface.
I am going through a couple of books at the moment trying to teach
myself a little vb.net. Just for the heck of it, ya know. Kinda
interesting stuff. Anyhoo; Both of these talk about what an interface
is, give an example, and then happily go on their merry way leaving me
to guess as to WHY you would create and use one?
How is;
Public Interface IJunk
Sub MoreJunk()
End Interface
Public Class UseJunk
Implements IJunk
Public Sub MoreJunk() Implements Ijunk.MoreJunk
End Class
Any different than Just;
Public Class UseJunk
Public Sub MoreJunk()
End Class
????
Other than more typing that is. 12 1683
Here's one situation where I just used an interface (literally like 10
minutes ago).
I'm migrating code from VB6 to VB.NET and the code builds a tree of
school district names. The tree is usually just one level but
sometimes it's two levels where we group districts. The old VB6 code
looked basically like this;
for each district
... if grouped then
... .. add to group
... else
... .. add directly to root
... end if
next
but this is a waiste of cpu since the if is inside the loop. To solve
this in .NET I used an interface (which I could have done in VB6 too,
but I hadn't read GOF then).
VB.NET code:
dim filler as IFiller
if grouped then
... filler = new GroupedFiller()
else
... filler = new PlainFiller()
end if
for each district
... filler.Add(dist rict)
next
and I have
interface IFiller
class GroupedFiller implements IFiller
class PlainFiller implements IFiller
This way, the code code above can act on an instance of IFiller the
same way regardless of whether the actual instance is one of
GroupedFiller or PlainFiller.
HTH,
Sam
On Fri, 7 Jan 2005 13:34:33 -0600, you <yo*@me.com> wrote: I may be just stupid, but I don't understand the point of using an Interface.
I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
"This is what interfaces provide: a way to inherit just a set of method and property
specifications with no implementation to worry about and no problem inheriting from as
many interfaces as you need." http://msdn.microsoft.com/library/de...interinher.asp
"you" <yo*@me.com> wrote in message news:MP******** *************** *@news.microsof t.com... I may be just stupid, but I don't understand the point of using an Interface.
I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
How is;
Public Interface IJunk Sub MoreJunk() End Interface
Public Class UseJunk Implements IJunk Public Sub MoreJunk() Implements Ijunk.MoreJunk End Class
Any different than Just;
Public Class UseJunk Public Sub MoreJunk() End Class
????
Other than more typing that is.
think of an interface as a class template.
it allows you to make sure all classes that use the interface are created
in a consistent fashion.
you are indicating with an interface that the class behave in a particular
way, but unlike inheritance, the class itself will provide the
implementation.
check out the ICloneable, IComparable, IDisposable interfaces in help for
some good real world uses.
"you" <yo*@me.com> wrote in message
news:MP******** *************** *@news.microsof t.com... I may be just stupid, but I don't understand the point of using an Interface.
I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
How is;
Public Interface IJunk Sub MoreJunk() End Interface
Public Class UseJunk Implements IJunk Public Sub MoreJunk() Implements Ijunk.MoreJunk End Class
Any different than Just;
Public Class UseJunk Public Sub MoreJunk() End Class
????
Other than more typing that is.
think of an interface as a class template.
it allows you to make sure all classes that use the interface are created
in a consistent fashion.
you are indicating with an interface that the class behave in a particular
way, but unlike inheritance, the class itself will provide the
implementation.
check out the ICloneable, IComparable, IDisposable interfaces in help for
some good real world uses.
"you" <yo*@me.com> wrote in message
news:MP******** *************** *@news.microsof t.com... I may be just stupid, but I don't understand the point of using an Interface.
I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
How is;
Public Interface IJunk Sub MoreJunk() End Interface
Public Class UseJunk Implements IJunk Public Sub MoreJunk() Implements Ijunk.MoreJunk End Class
Any different than Just;
Public Class UseJunk Public Sub MoreJunk() End Class
????
Other than more typing that is.
An interface provides a contract for how an object will present itself to
the outside world.
This is very useful in an object oriented system where objects may be
derived from many different base-classes. Each of the bases have their own
behaviours and don't necessarily have the same capabilities as the next
object. If however you wanted to make sure that all objects could do the
same thing no matter what their ancestry you can use an interface.
Consider the situation where you wanted to create an extensible
architecture. One method is to create a base class and force everyone who
want's to make a plug-in derive their objects from that base. Another is to
provide an interface, say IPluggable, and tell everyone that the only thing
you need to do to make a plugin is to implement IPluggable.
The interface method is way more flexible because you don't impose any
implementation baggage on the architecture and all you specify is how the
object should appear to behave.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"you" <yo*@me.com> wrote in message
news:MP******** *************** *@news.microsof t.com... I may be just stupid, but I don't understand the point of using an Interface.
I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
How is;
Public Interface IJunk Sub MoreJunk() End Interface
Public Class UseJunk Implements IJunk Public Sub MoreJunk() Implements Ijunk.MoreJunk End Class
Any different than Just;
Public Class UseJunk Public Sub MoreJunk() End Class
????
Other than more typing that is.
Have you ever used Adobe Photoshop? or any graphics app that has
"plugins"?
Plugins for these apps are typically written by third parties but in
order to work correctly in Photoshop, they must be written in a certain
way.
Photoshop, then, would define the interface, that is a specification
for a list of functions and properties that the plugin author must use,
or implement.
As long as the plugin writer follows the interface, then Photoshop will
be able use the plugin. Adobe has no idea about how the plugin works,
it just knows that it can call certain methods and get certain data
back in return. In other words, Photoshop doesn't have to know about
the internal workings of the plugin.
By the same token, the plugin doesn't have to know about the internal
workings of Photoshop either. All it knows is that Photoshop will call
a certain method and pass in certain data. The plugin then takes that
data, manipulates it however it wants, and returns data back to
Photoshop. What it returns is defined by the interface.
The whole point is that, Adobe publishes the interface, and third party
developers can develop to that interface with little or no help from
Adobe.
Chris
you,
To tell the same as all others with other words.
An interface tells exactly what should be at least in a class to be confirm
that interface.
Cor
you,
To tell the same as all others with other words.
An interface tells exactly what should be at least in a class to be confirm
that interface.
Cor
"you" <yo*@me.com> wrote I am going through a couple of books at the moment trying to teach myself a little vb.net. Just for the heck of it, ya know. Kinda interesting stuff. Anyhoo; Both of these talk about what an interface is, give an example, and then happily go on their merry way leaving me to guess as to WHY you would create and use one?
In short, an interface is a connection point in software, much like the
modem jack, or keyboard jack are for hardware. The RJ11 (or which ever)
jack the telephone uses is standardized so that anything that responds like
a telephone can use the jack. Because the jack is standard, many others can
build on to the telephone network (Modems, Faxes, Telephones, etc.) and
can add their own features to whatever devices they build.
The same for the electrical wall outlet. The whole house has electricity,
but the interface is just the 3-pronged plug (in the U.S.) which any device
can use. That type of plug indicates there is about 120V of AC (60 Hz)
available. Anybody who builds a device can plan on using 120V AC through
that type of interface. Washers, dryers, and funaces may use 240V AC
and they have a different interface (a different style of outlet).
Having such a connection point allows for later mixing and matching between
major pieces of the whole. Whether that is different devices in your house,
or different software for your computer.
LFS This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: (Pete Cresswell) |
last post by:
I've been perusing a "real-life" application and notice that for instance, in a
button's Click() event, they don't write the processing code. Instead, they
raise an event like AddNewRecord and then put the coding that would have been in
the click event in the AddNewRecord event handler.
It seems TB throughout the app, so I'm guessing it's some sort of Best Practice.
Anybody care to explain?
--
PeteCresswell
|
by: milkyway |
last post by:
Hello,
I have an HTML page that I am trying to import 2 .js file (I created)
into. These files are: row_functions.js and data_check_functions.js.
Whenever I bring the contents of the files into this HTML file, all is
OK but whenever the functions are separated (as it is now), when I run
the page, I get the following error:
Line 73, object expected.
|
by: J Allen Horner |
last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an
example:
-----------
#include <stdio.h>
#define MAX 10
int a;
int rand_seed=10;
|
by: steve |
last post by:
i'd like to inherit from a class while changing the access-level of an
interface within the derived class. the below won't work...how do i properly
do this...i don't want to expose the "add" method of the "InheritedItems"
class to a caller even though i inherit from the "Items" class which has a
different access-level. i understand why this is a problem but don't know
how to accomplish what i've explained above as what i want to do. i...
|
by: jason |
last post by:
I found the below example online, while trying to under Interfaces.
In layman's terms, can somebody explain what the purpose of this line
is:
void SportCharacteristics(); //LOCATED IN THE Iball interface.
... I read its a method without an implemetnation.. like an abstract I
think.. so how does it serve this project?
| |
by: davetelling |
last post by:
I am not a programmer, I'm an engineer trying to make an interface to a
product I'm designing. I have used C# to make a form that interrogates the
unit via the serial port and receives the data. I want to be able to draw
lines in a picturebox based upon certain data points I have received. I
dragged a picturebox from the toolbar onto my form, but after having gone
through the help files, looking online and trying a variety of things, I...
|
by: DJP |
last post by:
Hi,
I had sort of a noob question on memory allocation for strings.
char *str1 = "Hello World!";
char str2 = "Hello World!";
In the above bit are both str1 & str2 stack allocated or heap allocated
or otherwise? Also, unless explicitly malloc'ing a string buffer are we
not required to free it? Or are there other circumstances in which we
|
by: Hydrogenfussion |
last post by:
Hello and thank you for reading this.
I have just started to learn C++ from www.cprogramming.com,its a great site!
But i do not understand some of the terms.
I am using Dev-C++.
Can you tell me where to go to understand C++ terms? TY
When i said i was a noob i meant it.
This is the ONLY thing i have written:
#include <iostream>
using namespace std;
|
by: Carnell, James E |
last post by:
I am thinking about purchasing a book, but wanted to make sure I could
get through the code that implements what the book is about (Artificial
Intelligence a Modern Approach). Anyway, I'm not a very good programmer
and OOP is still sinking in, so please don't answer my questions like I
really know anything.
MY QUESTION:
What is a slot? In class Object below the __init__ has a slot. Note:
The slot makes use of a data object called...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |