473,790 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Erm, how do you know when to make an interface? :-)

Festive greetings fellow programmers!

I've been programming now for about 4, maybe 5 years now. 4 of those years
were at university so and I havent had much work experience of making real
world applications (although I trying to make some now). There is still a
lot I don't know when it comes to making programs. I know all the theory,
but not how (and why) certain things are done in real world projects.

My current ponderings are about interfaces. I think I understand the
theory -

An interface is used to define a contract between two entities. One entity
implements an interface, and the other entity can program against that
interface and know that whatever object is there at runtime - as long as the
interface is implemented - everything will be fine.

Well, thats nice then. I can understand why that might be a good idea on
occasion (in theory). You being able to say - "Ok, I don't want to know what
the actual object is as such; I just want to know that it will fulfill its
obligations".

The thing I'm crap at is - knowing when to create an interface.

How do you know? What objects should have interfaces made for them? I havent
got a clue because I was never taught about it.

I'm currently trying to make an email application that will store received
messages on the file system. I'm trying to figure out if I should make any
interfaces - but I just don't know.

I could make an interface for loads of objects, but I'm not sure what the
point would be. I'm sure I should have at least some interfaces, but I don't
know where to make them and so on. It's really a problem of implementation.

Could anyone offer me some general advice on how you can spot potential
interfaces. I mean, there must be some approach to it; some sort of rules
that developers either conciously or subconsiously apply. If anyone could
offer any advice at all on how to spot/determine when an interface should be
employed, then that would be excellent.

Many thanks to anyone who can help.

Kind Regards

Simon
Jul 21 '05
20 2277
You where asking about rules that help you choose when to use interfaces
Here are some:

1- If you're going to work with lots of objects that have the same behavior
an will share some implementation use Inheritance. Example: drawing
applications, all the objects in a canvas need behavior for moving,
resizing, etc...

2- If working with lots of objects, and all objects may be very diferent in
implementation and may be internally composed of many other objects but all
define a custom behavior use an interface. Example: Plugins for an
application.

3- If some of the classes that you'll use are already inherited from other
classes; then use interfaces, multiple inheritance is not possible in C# at
least. Example: Creating a group of custom controls (some controls derived
from UserControl, other's from a TextBox maybe).

4- Don't Create an interface if there is no reason to do it. Objects that
will be useful to implement an interface are the ones that will be stored on
Collections ( which will be later enumerated to work with the elements) or
the ones that will be produced or used by another class that only need to
know the behavior of different types of objects.
"Simon Harvey" <sh856531@micro softs_free_emai l_service.com> wrote in message
news:uN******** ******@tk2msftn gp13.phx.gbl...
Festive greetings fellow programmers!

I've been programming now for about 4, maybe 5 years now. 4 of those years
were at university so and I havent had much work experience of making real
world applications (although I trying to make some now). There is still a
lot I don't know when it comes to making programs. I know all the theory,
but not how (and why) certain things are done in real world projects.

My current ponderings are about interfaces. I think I understand the
theory -

An interface is used to define a contract between two entities. One entity
implements an interface, and the other entity can program against that
interface and know that whatever object is there at runtime - as long as the interface is implemented - everything will be fine.

Well, thats nice then. I can understand why that might be a good idea on
occasion (in theory). You being able to say - "Ok, I don't want to know what the actual object is as such; I just want to know that it will fulfill its
obligations".

The thing I'm crap at is - knowing when to create an interface.

How do you know? What objects should have interfaces made for them? I havent got a clue because I was never taught about it.

I'm currently trying to make an email application that will store received
messages on the file system. I'm trying to figure out if I should make any
interfaces - but I just don't know.

I could make an interface for loads of objects, but I'm not sure what the
point would be. I'm sure I should have at least some interfaces, but I don't know where to make them and so on. It's really a problem of implementation.
Could anyone offer me some general advice on how you can spot potential
interfaces. I mean, there must be some approach to it; some sort of rules
that developers either conciously or subconsiously apply. If anyone could
offer any advice at all on how to spot/determine when an interface should be employed, then that would be excellent.

Many thanks to anyone who can help.

Kind Regards

Simon

Jul 21 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
4856
by: The Plankmeister | last post by:
Is doing this bad: <h3>Some title or other...<a href="#pagetop">back to top</a></h3> I have a feeling it is... My problem is I'm using CSS to style the H3 into a block that spans the whole containing element. I would like the <a> to appear next to the title, but I'm sure this is bad practice (for screen readers and heading-level navigation etc etc) So... is it acceptable to do this:
11
2168
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain methods, such as public void Add(MyClass c). How can I enforce the same behavior (of requiring to implement a member with a new return type in an inherited class) in the master class (similar to the CollectionBase)? I have a class called...
20
1305
by: Simon Harvey | last post by:
Festive greetings fellow programmers! I've been programming now for about 4, maybe 5 years now. 4 of those years were at university so and I havent had much work experience of making real world applications (although I trying to make some now). There is still a lot I don't know when it comes to making programs. I know all the theory, but not how (and why) certain things are done in real world projects. My current ponderings are about...
7
1291
by: Micheal | last post by:
Hi, I want to know about news groups of visual studio.net 2005 . regards micheal
4
1652
by: Mario Vázquez | last post by:
Hi all, I'm trying to build a component which takes advantage of other components. So, when this new component is draged to the form, I would like to insert other components on the designer and relate them. But only the first time the component is inserted! to avoid inserting components each time de form is loaded in the IDE. How can I hook the very first time a component is draged on a windows form? Thanks for attention, Mario Vazquez
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
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...
0
9986
tracyyun
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...
0
9021
agi2029
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...
1
7530
isladogs
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...
0
6769
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();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.