Saturday, January 8, 2011

Abstract Class Usage for Process to Library Communication

Problem statement:
A process is doing lots of different functionalities, and each functionality is a library. So, In general we allways write a interface class where in the both will talk to each other.
Let us suppose library want to use some facilities of Main Process . Then
1) write an abstract class with the functions which needs to be implemented by main process
2) Main process will inherit this abstract class and main process code will implement these functions.
3) Make sure that this abstract class will have initized function which will be called by Main Process by passing its own this pointer.
So, now this abstract class will always holds the main process class pointer.
4) When ever library wants to avail the main process services, we can get those using the this pointer which it is received. (Any how Main Process class is already inherited and implemented in main process code)
//Main Process
Class Main:: public SumServiceCallBackLibrary  //Mainclass is inherited AbstractClassCallBack
        public :
                void initializeSubModule1()  {
   cout << "Main class received message from library to shut down the system";
//abstract class which is also interface between library and process
Class SumServiceCallBackLibrary 
virtual void  startShutdown() = 0;
Class LibraryClass
    Initalize(SumServiceCallBackLibrary  * r_cbPtr)  { m_pcSSCBptr= r_cbPtr; }
    initiateShutdown() {
        m_pcSSCBptr->startShutDown();  //Here we are calling the implmentation of main process.
    SumServiceCallBackLibrary  *m_pcSSCBptr;

No comments:

Post a Comment