implementing Java's Observable in C/C++?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Digital Puer

    implementing Java's Observable in C/C++?

    I have to convert some existing Java code into C/C++. One of the
    Java classes implements Observable. Can someone suggest how
    I might write this in C/C++? I'm thinking I would need something
    like function pointers, but I've never used those... Thanks for
    any help.



  • Peter Ashford

    #2
    Re: implementing Java's Observable in C/C++?

    Digital Puer wrote:[color=blue]
    > I have to convert some existing Java code into C/C++. One of the
    > Java classes implements Observable. Can someone suggest how
    > I might write this in C/C++? I'm thinking I would need something
    > like function pointers, but I've never used those... Thanks for
    > any help.
    >
    >
    >[/color]

    Why would you need function pointers?

    Interfaces and base classes can be translated into C++ fairly directly.
    Use std::vector to hold your observables and iterate through them when
    doing notification.

    I don't see where your issue is - I'd do this in C++ in almost exactly
    the same way I'd do it in Java (this is a design pattern, not a language
    issue)

    Peter.

    Comment

    • Steven T. Hatton

      #3
      Re: implementing Java's Observable in C/C++?

      Digital Puer wrote:
      [color=blue]
      > I have to convert some existing Java code into C/C++. One of the
      > Java classes implements Observable. Can someone suggest how
      > I might write this in C/C++? I'm thinking I would need something
      > like function pointers, but I've never used those... Thanks for
      > any help.[/color]

      Do you know how to implement the event/listener pairs in Java from scratch?
      Do the same with C++. If you aren't threading, then you don't need to
      worry about /synchronized/ methods. Use javap on the commandline to get a
      clear view of the class's interface.
      --
      p->m == (*p).m == p[0].m

      Modernize your infrastructure with SUSE Linux Enterprise servers, cloud technology for IaaS, and SUSE's software-defined...

      Mozilla is the not-for-profit behind the lightning fast Firefox browser. We put people over profit to give everyone more power online.

      Comment

      Working...