This is a mirror of official site: http://jasper-net.blogspot.com/

Interface-based programming, Runtime class discovery, Dynamic class loading from DLL

| Tuesday, February 1, 2011
Introduction

Interface-based programming is a well-known paradigm that has been around for a long time and it is a core technology behind frameworks such as COM or CORBA.

Interface-based programming (IBP) defines the application as a collection of independent modules which plug into each other via interface. Modules can be unplugged, replaced, or upgraded, without the need of compromising the contents of other modules. This reduces the complexity of the system and greatly increases maintainability at a later development cycles.

IBP is convenient. It is convenient when each module of a larger application must be developed by different teams. Even with the different versions of compilers and compilers in whole. You will be able to create flavors of your application like Basic, Standard, or Enterprise with the same core binary code base. When you publish your interface to a larger developer community, they can start creating additions to your software with ease thus further enhancing its market value. It’s just one big bang for a buck any way you look at it.

What I will describe in this article is COM-like mechanism without the COM baggage. You may find this article interesting if you:
·         Must develop and maintain application in C++
·         You do not need language interoperability with higher languages like VB/C# etc.
·         You want the interface-based modularity just like COM but do not want the peculiarities and baggage of COM to come along with it.

What you will gain vs. COM is:
·         No need for messy registration of modules
·         You are not limited to base IUnknown class
·         You do not have to return HRESULT from every operation
·         Encapsulation at binary level

In order to achieve these goals your core application must be able to:
·         Discover classes during runtime
·         Dynamically load unknown classes that are not exported  from DLL
·         Enable discovered classes to pass events back to application or among each other

Delete the discovered classes and unload the DLL when no longer needed


Background

What I have discovered over time is that the COM is awkward for simple things.

Runtime class discovery

When your main application wants something done it knows which interface can do the job. Interface is nothing more but a class of pure virtual functions with no implementation and no data members.  Because the interface is a singular entity and the implementation of that interface can be a plural entity, invoking application must know one more piece of information about that interface. This 2nd piece of information is the implementation identity, or commonly known as GUID (globally unique identifier). It is possible to use the string names instead but it’s not a good idea. You want an id that collides with other ids every say other 10,000 years. 128 bit GUID should do the trick.


Read more: Codeproject

Posted via email from Jasper-net

0 comments: