How to expose the interfaces to the client

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    #1

    How to expose the interfaces to the client

    Hi,

    Currently I have designed the classes for my application.But how to give the access to my application to the client side,without exposing my implementation of the classes.I hope that thru interface concept we can implement it.But I am new for doing Client and server application development.

    Could anybody help me i doing the client and server side development.Wit h simple example

    Thanks in advance
    PSB
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by psbasha
    Hi,

    Currently I have designed the classes for my application.But how to give the access to my application to the client side,without exposing my implementation of the classes.I hope that thru interface concept we can implement it.But I am new for doing Client and server application development.

    Could anybody help me i doing the client and server side development.Wit h simple example

    Thanks in advance
    PSB
    Message passing is a good option. Although it's not in the language, you can implement one function to recieve messages and process as a "select". A neat trick is for the sender to supply the function to be called upon completion:
    Code:
    class server:
        def receive(replyFunction, msgNumber, *args):
            # process msgNumber
            replyFunction(msgNumber, result1, result2)
    class client:
        def callbackFunc(self, msgNumber, *expectedResults):
            # process reply
    
        def mainLoop():
            self.server.receive(callback, 1,arg1, arg2)
    My classes always end up with 4 to 8 "Getters" and "Setters" so that I don't end up doing this:
    Code:
    server.variable = value

    Comment

    • psbasha
      Contributor
      • Feb 2007
      • 440

      #3
      I have a class by name Point3D in Python.

      class Point3D :
      def __int(self):
      self.__x =0.0
      self.__y =0.0
      self.__z =0.0

      def setPoint(x,y,z) :
      self.__x =x
      self.__y =y
      self.__z =z

      def getPoint(x,y,z) :
      x = self.__x
      y = self.__y
      z = self.__z

      I dont want to expose the above Point3D implementation to the user /client side.To achieve that we can use interface concept.In Python to use interface concept.

      How the interface class looks like for Point3D in python?.

      How to implement that Interface?

      How to access the implemented interface thru Interface Object in the client side?

      It will be helpful if somebody proivide a piece of sample code for creating the interface for the above access at the client place

      in C++ these can be done in this way

      class IPoint : public IUnknown{
      virtual void setPoint(int x,int y,int z)=0;
      virtual void getPoint(&x,&y, &z)=0;
      }

      class Point3D: public IPoint {
      private :
      float _x ,_y,_z;
      public:
      void Point3D() {
      _x=_y=_z =0
      }
      void setPoint(int x,int y,int z){

      _x =x
      _y =y
      _z =z


      }
      void getPoint(&x,&y, &z){
      x = _x
      y = _y
      z = _z
      }
      }

      Thanks in advance

      PSB

      Comment

      • psbasha
        Contributor
        • Feb 2007
        • 440

        #4
        I forgot to access the Point data in the client side

        IPoint *pIPoint = NULL;
        pISampleInterfa ce = CoCreateInstanc e(..);
        ...............
        pISampleInterfa ce ->QueryInstance( IID_IPoint ,(void*&)pIPoin t )

        // We have the pIPoint interafce
        float dX =0,dY=0,dZ=0;

        pIPoint->setPoint(10,20 ,30);

        pIPoint->getPoint(&dX ,&dY,&dZ);

        printf ( "%f,%f%f",d X ,dY,dZ);

        10.0 20.0 30.0


        Thanks
        PSB

        Comment

        Working...