473,657 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

abstract class, implementing virtual class loaded at runtime

I am trying to write several hardware interfaces that
would use the same base class and functions and be
implemented differently. I don't want to ship all of the
interfaces, but want to access them using the same generic
base class.

I have seen that I can use the Assembly.load method to
load the implementation I need for the hardware being
connected to, but wish to write the code such that I can
reference the methods of the class directly, and take
advantage of strong typing, etc. I don't see where using
dynamic loading of an assembly I can subsequently hook up
my strongly typed code to that assembly code.

Can I create this class from the loaded assembly and then
reference it using only the abstract class (eliminating
the requirement for the main compilation to know anything
about the derived class)?

The problem I am running into is how to allow the app to
switch between derived classes, without them all being
compiled in. Even the problem of instantiating them
correctly is befuddling me.

Here is an example:

namespace test
{
/// <summary>
/// base class for HW ctrl
/// </summary>
public class HWCtrl
{
public HWCtrl()
{

}

public virtual bool Run()
{
return true;
}
}
}

Now in a separate assembly:

namespace test
{
/// <summary>
/// derived class for HW ctrl
/// </summary>
public class DerivedHW : HWCtrl
{
public HWCtrl()
{

}

public bool Run()
{
return true;
}
}
}

I want to drop in the proper assembly for the job, and
bind to it at run time. Maybe this is easy, maybe it's not
possible, but I can't seem to find the answer in the
libraries or the web.

I have thought about using identical GUIDs for all the HW
implementations and creating a class interface, but that
seems to create its own problems.

Anyone been here before?

Thanks in advance,

Robb Sadler

Nov 15 '05 #1
2 7106
Robb Sadler <rs*****@mrgiga .com> wrote:

<snip>
I want to drop in the proper assembly for the job, and
bind to it at run time. Maybe this is easy, maybe it's not
possible, but I can't seem to find the answer in the
libraries or the web.


I *think* your question is answered in
http://www.pobox.com/~skeet/csharp/plugin.html
- which tries to answer a different question, but answers yours on the
way anyway. Try going through the example and see whether that does
what you need it to.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Thanks Jon!

That was exactly what I was looking for. I was pretty sure
it could be done and looked in the MSDN for hours trying
to find the proper stuff to implement it. If I had known
to look for the keyword "CreateInstance " I would have been
all set as I found out with a quick search after the fact.

Many thanks, I have what I need.

Best regards,

Robb

I *think* your question is answered in
http://www.pobox.com/~skeet/csharp/plugin.html


Nov 15 '05 #3

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

Similar topics

10
2552
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class forgets to implement some method I normally get a compile error(if the class is created in some way of course). When using the Visual Studio 6 compiler however, it does not generate a compile error in this case: - I have a implementing class A...
33
3333
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or near-impossible. It seems like it would be useful. In fact, there's a place in my code that I could make good use of it. So why not? Chris
6
5798
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove the need to have abstract class types in C#? Derived classes from abstract base classes must overrided the abstract method defininition anyway, so why not just provide a complete definition for the abstract method when defining the containing...
4
1508
by: Rachel Devons | last post by:
All, I'm struggling with an OOP concept. Let me try to define what I'm wanting by using some classic examples. Let's say that I have classes called Square & Circle that derive from class Shape. Within class Shape, it has a method called Save to save the object to disk. It's defined in Shape because the logic to save the shapes is uniform across all shapes. Furthermore, let's say I've defined an interface called IDraw that includes
7
4463
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears to be checking that the correct data type is used DataAcess sets an abstract class and methods
2
2261
by: talkingpidgin | last post by:
I am trying to figure out why it is not conventional to use protected constructors in abstract classes since the only time they should be called is by the constructors of it's derived classes. Is it simply because it's not strictly necessary since an abstract class can't be instantiated anyways? It just seems like it would be clearer to make the ctor protected so I figured there must be some reason for it. Also I am trying to put...
4
1718
by: Arne Schmitz | last post by:
If i have an abstract base class, that only contains pure virtual methods (and maybe some non-virtual methods), is a vtable still being generated, for the first derived class that implements those pure virtuals? My idea is that as long as there are less than two virtual methods of the same name in existance, it would (in theory) not be necessary to build a vtable, thus eliminating the need for a lookup during runtime. Arne --
4
6565
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this right? And, why not use "new" instead of using "virtual"? And the last question, what is the differences between a abstract method and a interface?
8
1718
by: puzzlecracker | last post by:
0) What is the convention name for derived classes? 1) If we implement methods in abstract class, do we still need to declare them as abstract? 2) Are we allowed to override methods in derived classes that are already implemented in abstract? 3) Are there a different accessibility levels when I inherit class, like (public, protected, private), like class A:public B? Thanks
0
8316
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8737
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
8610
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
7345
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
6174
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
4168
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
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.