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 20 1305
Simon Harvey wrote: The thing I'm crap at is - knowing when to create an interface.
The moment I come across something that I think might make a case for
inheritance, I immediately backtrack and see if an interface makes more
sense. And it usually does.
There's no hard and fast rule. It should just be the first thing on your
mind when you discover a need for uniform behavior from disparate
objects. For example, if your email app will support plugins, you'll
want to develop an interface so you can operate those plugins without
knowing anything about them.
--
There are 10 kinds of people. Those who understand binary and those who
don't. http://code.acadx.com
(Pull the pin to reply)
If you want to define a "look and feel" without actually determining what a
certain look means or what a certain feel does then use interfaces.
"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
As far as object-oriented programming can be seen as an attempt to make
analogies between programming languages and the real world, interfacing vs.
inheritance can be seen as the difference between an object _being_
something and an object _doing_ something. If a class, A, is able to do
*foo*, and another class, B, needs to use a number of different objects that
do *foo*, the behavior, foo, should be an interface, so that different
classes than A can implement the interface, and B will be able to use them
all. However, if class B needs not classes that *do* foo, but classes that
*are* bar, then inheritance is more appropriate for the situation. It's up
to you to decide where to draw the line between behavior and identity.
Chris C.
To expand on this, consider if there will need to be some logic higher in
the class structure that will need to be handled by all similar types.
Interfaces are great if your classes will have self-contained logic,
otherwise you might consider a class hierarchy.
Also, remember that C# does not support multiple inheritance, so you also
need to identify behaviors that may be independent but need to be
implemented on the same class.
"Frank Oquendo" <fr****@acadxpi n.com> wrote in message
news:ef******** ******@TK2MSFTN GP10.phx.gbl... Simon Harvey wrote:
The thing I'm crap at is - knowing when to create an interface.
The moment I come across something that I think might make a case for inheritance, I immediately backtrack and see if an interface makes more sense. And it usually does.
There's no hard and fast rule. It should just be the first thing on your mind when you discover a need for uniform behavior from disparate objects. For example, if your email app will support plugins, you'll want to develop an interface so you can operate those plugins without knowing anything about them.
-- There are 10 kinds of people. Those who understand binary and those who don't.
http://code.acadx.com (Pull the pin to reply)
> How do you know? What objects should have interfaces made for them? I
havent got a clue because I was never taught about it.
Create an interface when you cannot (or do not want to) rely on a specific
object hierarchy.
For example, most of the applications I write are for use in both Windows
and the Web. In my Windows apps I store end-user settings on the local
machine, however in Web apps I store them in cookies.
This brings up a dilemma - how do I access end-user preferences uniformly?
In other words, I want a single code-base for Windows apps and Web apps. To
do this, I define an interface. Here's an example:
public interface IEndUser : object
{
string Name{
get;
set;
}
Color FavoriteColor{
get;
set;
}
// ... whatever ...
}
Now I can write two objects, both implementing IEndUser. One will be for
Windows and the other for the Web, and I can share any code which uses the
interface between applications.
Another use for interfaces is the ability to test for certian functionality.
For example, you have a method which works for any object, but if the object
implements IDoThisToo then you could use the IDoThisToo interface to
implement special features.
--
-Jimmy
Wow! I didnt expect that many replies. I only posted this an hour or so ago!
Thanks for that everyone. Two quick questions:
1. When should I use an abstract class instead of an interface
2. Given that I understand the theory, can anyone suggest some good books on
actual *implementation *. The theory behind these topics is all relatively
simple, but where I (and many others) fall down is actually knowing when,
where and why to apply the theory to actual real world problems.
I think what I would definately benefit from would be a book or tutorial
that discusses a real world application and where/why certain OO mechanisms
were employed. E.g. "We're going to define an Interface here because ....X
.....Y ..... Z. This will allow us to blahh blahh blah further down the
line".
I havent really ever found a book or online resource that discusses this
sort of stuff at the level I need. I mean there are reference applications
from MS and Sun, but they are all focused on showing off their fancier
features like RMI, web services, distributed programming/remoting and so on.
I just need something that talks about some everyday applications and how
they were built from an architectural point of view.
Thanks guys
Simon
> 1. When should I use an abstract class instead of an interface 2. Given that I understand the theory, can anyone suggest some good books
on actual *implementation *. The theory behind these topics is all relatively simple, but where I (and many others) fall down is actually knowing when, where and why to apply the theory to actual real world problems.
I think what I would definately benefit from would be a book or tutorial that discusses a real world application and where/why certain OO
mechanisms were employed. E.g. "We're going to define an Interface here because ....X ....Y ..... Z. This will allow us to blahh blahh blah further down the line".
I havent really ever found a book or online resource that discusses this sort of stuff at the level I need. I mean there are reference applications from MS and Sun, but they are all focused on showing off their fancier features like RMI, web services, distributed programming/remoting and so
on. I just need something that talks about some everyday applications and how they were built from an architectural point of view.
Thanks guys Simon
> 1. When should I use an abstract class instead of an interface
Use an abstract class when you need to provide actual class logic as well as
an interface. If you can make your abstract base class do most of what you
need your child classes to do, with slight modifications or additions, then
this is the way to go. 2. Given that I understand the theory, can anyone suggest some good books
on actual *implementation *. The theory behind these topics is all relatively simple, but where I (and many others) fall down is actually knowing when, where and why to apply the theory to actual real world problems.
I'd say look at the .NET framework. Particularly the ICollection,
IDisposable, and other widely used interfaces.
As far as actual books go, I'm not a good resource. But search for "design
patterns" and "object oriented", and you're sure to find something good.
Chris C.
On Mon, 22 Dec 2003 23:00:17 -0000, "Simon Harvey"
<sh856531@micro softs_free_emai l_service.com> wrote:
<snip> I havent really ever found a book or online resource that discusses this sort of stuff at the level I need. I mean there are reference applications from MS and Sun, but they are all focused on showing off their fancier features like RMI, web services, distributed programming/remoting and so on. I just need something that talks about some everyday applications and how they were built from an architectural point of view.
Thanks guys Simon
Take a look at Applied Microsoft .NET Framework Programming, by
Jeffrey Richter, if you haven't already. Few books can measure up to
the quality of it. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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...
|
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...
|
by: Micheal |
last post by:
Hi,
I want to know about news groups of visual studio.net 2005 .
regards
micheal
|
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
| |
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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...
|
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: 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: 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: 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...
|
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
| | |