473,398 Members | 2,368 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,398 software developers and data experts.

Instantiation via Class Name

All

Good day to everyone!

I am developing a system which interfaces with various external systems. The
set of external systems will change and grow over time. I will produce a new
class to represent each of these external systems, and each of these
classes will implement an interface that I have designed (IExternalAccount).
What I want to do is ensure that a) I need to make minimal code changes in
order to introduce a new implementation of the interface IExternalAccount to
the system, and b) I can control which external systems are included in my
system via my config file.

The approach that I'm taking is to have an entry in the config file, the
value for which is a comma delimited list of class names. I access this
value from my code, then create an object instance of each of the classes
listed. These are then added to a collection, and then processed.

My questions are:

1. Is this a good approach?

2. Can someone suggest how to implement this design (or point me in the
right direction)?

Many thanks in advance for your assistance!

--
Regards

Chris Marsh
May 15 '07 #1
4 1357
Chris,
>1. Is this a good approach?
The general idea is fine and quite common solution for a dynamic,
pluggable architecture.

I'm not sure I'd use a single comma-separated string to hold all class
names though, at least if you need fully qualified type names (if the
classes are implemented in different assemblies). It could easily
become very unreadable, and you can do better with XML.

>2. Can someone suggest how to implement this design (or point me in the
right direction)?
I'm sure you can find examples if you search for "add-in" or "plug-in"
(along with ".NET" and/or your programming language of choice).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 15 '07 #2
Hi Chris,

Yes, I agree with Mattias that your plan on using reflection to dynamically
load assembly and activate class instances(for pluggable system) is
reasonable. Most managed add-in like application adopt this design. Here
are some reference articles discussing on built pluggable /add-in system
through .net managed code:
#NET Based Add-in/Plug-in Framework with Dynamic Toolbars and Menus
http://www.codeproject.com/cs/librar...rojFrmwork.asp

#Managed AddIn Framework (MAF)
http://blogs.msdn.com/jackg/archive/...15/468068.aspx

and you can also look for some .NET reflection and dynamici code execution
related reference articles which are also helpful.

#Using reflection to extend .NET programs
http://www.codeproject.com/csharp/reflection.asp

#Programming with Application Domains and Assemblies
http://msdn2.microsoft.com/en-us/lib...ez(VS.71).aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


May 16 '07 #3

Most likely you'll want to write a custom configuration section.

12/1/2005
Understanding the Simple Factory Pattern
http://sholliday.spaces.live.com/blog/

You want #3
3. Using reflection. You can setup the concrete class in a configuration
file.

Code sample/download available at the blog.


"Chris Marsh" <cj*@newsgroup.nospamwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
All

Good day to everyone!

I am developing a system which interfaces with various external systems.
The
set of external systems will change and grow over time. I will produce a
new
class to represent each of these external systems, and each of these
classes will implement an interface that I have designed
(IExternalAccount).
What I want to do is ensure that a) I need to make minimal code changes in
order to introduce a new implementation of the interface IExternalAccount
to
the system, and b) I can control which external systems are included in my
system via my config file.

The approach that I'm taking is to have an entry in the config file, the
value for which is a comma delimited list of class names. I access this
value from my code, then create an object instance of each of the classes
listed. These are then added to a collection, and then processed.

My questions are:

1. Is this a good approach?

2. Can someone suggest how to implement this design (or point me in the
right direction)?

Many thanks in advance for your assistance!

--
Regards

Chris Marsh


May 16 '07 #4
All

Many thanks for the advice - valuable as always.

--
Regards

Chris Marsh
May 20 '07 #5

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

Similar topics

7
by: Hunter Hou | last post by:
Hello, I'm trying one example of <<the C++ programming language>> Page 865 int f( int ); template< class T > T g( T t ) { return f( t ); } char c = g( 'a' ); ************ char f( char ); ...
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
4
by: Steve Long | last post by:
Hello, I hope this is the right group to post this to. I'm trying to serialize a class I've written and I'd like to be able to serialze to both binary and xml formats. Binary serialization is...
5
by: Slant | last post by:
Here's a question that most will have different answers to. I'm just dying to find a solution that seems halfway automated!! There really are two seperate issues which might be answered by the...
4
by: Theo | last post by:
Hi, i created a custom attribute that accepts an argument in the constructor to fill a property. The constructor is supposed to be called when then attribute is set but that doesn't seem to happen....
3
by: Steven T. Hatton | last post by:
Has anybody here used explicit instantiation of templates? Has it worked well? Are there any issues to be aware of? -- NOUN:1. Money or property bequeathed to another by will. 2. Something...
1
by: krunalbauskar | last post by:
Hi, Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. For example - <snippet> #include <iostream> #include <vector>
6
by: Ritesh Raj Sarraf | last post by:
Hi, I've been very confused about why this doesn't work. I mean I don't see any reason why this has been made not to work. class Log: def __init__(self, verbose, lock = None): if verbose...
2
by: WittyGuy | last post by:
Hi My class looks something like this: class Base { public: Base () {} ~Base () {} // No virtual dtor in the base class private: };
4
by: yuanhp_china | last post by:
I define a class in A.h: template <class Tclass A{ public: void get_elem( const T&) ; };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
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,...

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.