473,395 Members | 1,527 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,395 software developers and data experts.

Interface problem in C#2.0

Hello everybody,

I have a problem with interface and I need urgent your help.

public interface IKoerper
{
// Properties
int laenge { get; }
int breite { get; }
int hoehe { get; }
int anzahl { get; }
// Methods
double errechneFlaeche();
void hinzufuegen(IKoerper koerper);
void entfernen(IKoerper koerper);
}
----DLL

public class Quadrat : IKoerper
{
// Variables
private int _laenge;
// // Properties
public int laenge { get { return _laenge; } }
public int hoehe { get { return 0; } }
public int breite { get { return _laenge; } }
public int anzahl { get { return 1; } }

// Methods
public Quadrat(int laenge)
{
_laenge = laenge;
}
public double errechneFlaeche()
{
return laenge * laenge;
}
}

----DLL

public class Rechteck: IKoerper
{
// Felder
private int _laenge;
private int _breite;
// Eigenschaften
public int laenge { get { return _laenge; } }
public int hoehe { get { return 0; } }
public int breite { get { return _breite; } }
public int anzahl { get { return 1; } }

// Methods
public Rechteck(int laenge, int breite)
{
_laenge = laenge;
_breite = breite;
}

public double errechneFlaeche()
{
return laenge * breite;
}
}

----DLL
Main program: -Exe
I want to call the function 'errechneFlaeche'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
In the case 1, the first DLL is inside the release folder,
my program calculate the Quadrat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
In the case 2, the second DLL is inside the release folder,
my program calculate the Rechteck
I'm not sure, for example I need a virtual class
VirtualClassApp AppCalc = new VirtualClassApp();
double result = AppCalc.errechneFlaeche();

How can I create the class, with a wizard.
Can you gibe me a simple and short instruction. Thanks.

Best regards Manuela
Nov 5 '06 #1
1 1228
Manuela Abele wrote:
Hello everybody,

I have a problem with interface and I need urgent your help.

public interface IKoerper
{
// Properties
int laenge { get; }
int breite { get; }
int hoehe { get; }
int anzahl { get; }
// Methods
double errechneFlaeche();
void hinzufuegen(IKoerper koerper);
void entfernen(IKoerper koerper);
}
----DLL

public class Quadrat : IKoerper
{
// Variables
private int _laenge;
// // Properties
public int laenge { get { return _laenge; } }
public int hoehe { get { return 0; } }
public int breite { get { return _laenge; } }
public int anzahl { get { return 1; } }

// Methods
public Quadrat(int laenge)
{
_laenge = laenge;
}
public double errechneFlaeche()
{
return laenge * laenge;
}
}

----DLL

public class Rechteck: IKoerper
{
// Felder
private int _laenge;
private int _breite;
// Eigenschaften
public int laenge { get { return _laenge; } }
public int hoehe { get { return 0; } }
public int breite { get { return _breite; } }
public int anzahl { get { return 1; } }

// Methods
public Rechteck(int laenge, int breite)
{
_laenge = laenge;
_breite = breite;
}

public double errechneFlaeche()
{
return laenge * breite;
}
}

----DLL
Main program: -Exe
I want to call the function 'errechneFlaeche'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
In the case 1, the first DLL is inside the release folder,
my program calculate the Quadrat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
In the case 2, the second DLL is inside the release folder,
my program calculate the Rechteck
I'm not sure, for example I need a virtual class
VirtualClassApp AppCalc = new VirtualClassApp();
double result = AppCalc.errechneFlaeche();

How can I create the class, with a wizard.
Can you gibe me a simple and short instruction. Thanks.

Best regards Manuela
Hi Manuela,

Here is a simple example:

Define the interface in a seperate assembly, e.g. ConsoleApplication.Api

namespace ConsoleApplication.Api
{
public interface IBody
{
double Volume { get; }
}
}

Put the implementations into seperate assemblies, e.g a cube into
ConsoleApplication.Cube.PlugIn:

using ConsoleApplication.Api;
namespace ConsoleApplication.Cube.PlugIn
{
class Cube : IBody
{
private readonly double length;
private readonly double width;
private readonly double height;

public Cube(double length, double width, double height)
{
this.length = length;
this.width = width;
this.height = height;
}
public double Volume
{
get { return width * length * height; }
}
}
}
implement your executing assembly:

using System;
using System.IO;
using System.Reflection;

namespace ConsoleApplication
{
class Program
{
static void Main()
{
string[] plugins =
Directory.GetFiles(
Environment.CurrentDirectory, "*.plugin.dll");

Assembly plugIn = Assembly.LoadFrom(plugins[0]);
foreach(Type possibleType in plugIn.GetTypes())
{
if (!typeof(IBody).IsAssignableFrom(possibleType))
continue;

// instantiate, assuming ctors contract takes
// length, width and height
IBody b =
(IBody) Activator.CreateInstance(
possibleType, 10.0, 10.0, 20.0);

Console.WriteLine(
string.Format("The Body has a volume of {0}!",
b.Volume));
}
}
}
}
Make sure that every assembly is build or copied into a common folder.
As you see, the plugins are loaded by name. You can change this to be
read from a config file.

HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Nov 5 '06 #2

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
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...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
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...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...

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.