473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

interface vs class

Hi,

I am creating a model to navigate a tree of symbols and links. My main
purpose of this post is to ascertain the quickest way of navigating the
tree. There are two ways that I am considering, see below. I am unsure
why you would implement interfaces in this design? Is it a performance
issue?

Simple method
-------------

The properties simply reference the actual link objects and symbol
objects.

public class Symbol
{
ArrayList listLinks
ArrayList listLinksEntering
ArrayList listLinksExiting
}

public class Link
{
Symbol fromSymbol
Symbol toSymbol
}

Interface method
----------------

The interfaces ISymbol and ILink implement the properties within each
class. The ICollection stores a collection of ILink references.

public class Symbol : ISymbol
{
ICollection listLinks
ICollection listLinksEntering
ICollection listLinksExiting
}

public class Link : ILink
{
ISymbol fromSymbol
ISymbol toSymbol
}
Thanks in advance.

Jimski

Nov 16 '05 #1
5 4195
Hi Jimski,

As I see it, I would use interfaces if I don't want to inherit from Symbol
or List when creating a "derived" class.
Otherwise I would preffer inheritance.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"Jimski" <ja*********@ukonline.co.uk> wrote in message
news:10**********************@z14g2000cwz.googlegr oups.com...
Hi,

I am creating a model to navigate a tree of symbols and links. My main
purpose of this post is to ascertain the quickest way of navigating the
tree. There are two ways that I am considering, see below. I am unsure
why you would implement interfaces in this design? Is it a performance
issue?

Simple method
-------------

The properties simply reference the actual link objects and symbol
objects.

public class Symbol
{
ArrayList listLinks
ArrayList listLinksEntering
ArrayList listLinksExiting
}

public class Link
{
Symbol fromSymbol
Symbol toSymbol
}

Interface method
----------------

The interfaces ISymbol and ILink implement the properties within each
class. The ICollection stores a collection of ILink references.

public class Symbol : ISymbol
{
ICollection listLinks
ICollection listLinksEntering
ICollection listLinksExiting
}

public class Link : ILink
{
ISymbol fromSymbol
ISymbol toSymbol
}
Thanks in advance.

Jimski

Nov 16 '05 #2
The difference won't be speed (although there is a tiny theoretical difference it won't be measurable) it will be flexibility. In the second you can use any type that implements ICollection, ILink and ISymbol rather than just the concrete classes you show in the first example. If you don't need that flexibility then stick with the first method as it is simpler to code in general and is slightly better for versioning if the various pieces are deployed in separate assemblies.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<10**********************@z14g2000cwz.googlegroups .com>

Hi,

I am creating a model to navigate a tree of symbols and links. My main
purpose of this post is to ascertain the quickest way of navigating the
tree. There are two ways that I am considering, see below. I am unsure
why you would implement interfaces in this design? Is it a performance
issue?

Nov 16 '05 #3
Thanks Richard.

The interface example comes from a component package that we have
bought. I guess when distributing components interfaces are useful.

Why would they affect the versioning when deployed in separate
assemblies?

Thanks
Jimski

Nov 16 '05 #4
If you add a method to an interface you break any implementors (this isn't an issue if you control all of the implementors, e.g they are in the same assembly as the interface). Adding methods to classes doesn't break anything unless you add an abstract member to a class.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<11**********************@f14g2000cwb.googlegroups .com>

Thanks Richard.

The interface example comes from a component package that we have
bought. I guess when distributing components interfaces are useful.

Why would they affect the versioning when deployed in separate
assemblies?

Thanks
Jimski

Nov 16 '05 #5
I see now.

Thanks for your help Richard

Nov 16 '05 #6

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

Similar topics

4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
3
by: Christof Warlich | last post by:
Hi, I'm looking for a more concise way than below to extend an existing interface. Just imagine that class Interface would have 1000 other members and class DerivedInterface only needs to add...
4
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two...
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
5
by: Colin McGuire | last post by:
Hi all, when I write the class below Private Class employee End Class and then add the line "Implements IVF" which is an interface I have written, the IDE modifies my code to display
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
8
by: rn5a | last post by:
Suppose I have the following class code: Imports System Imports System.Data Imports System.Data.SqlClient Public Class DBSettings Private sqlCmd As SqlCommand Private sqlConn As...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.