CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 1999
    Posts
    18

    User Supplied methods in Classes



    Hi All,

    I am a Java Beginner. I am trying to code up some numerical routines which expect to call some user supplied subroutines. What is the most appropriate way to do this in java. In fortan or C one would could declare an external function which the user would provide. Also in C one supply this by passing a pointer to a function. In C++ one could declare a virtual function of a class and derive a new class from it.


    I am having a single class that will contain all the numerical methods, but some of the methods will be calling user supplied funtions.


    1) One way could be to have the user create an object of some second class that is passed to the numerical method class which then owns it. The numerical methods class could then call the function supplied into the second class passed to it.


    Are there alternate ways in Java to handle having my class call the third party supplied functions? What are they?


    -Brad

  2. #2
    Join Date
    Jan 1999
    Posts
    2

    Re: User Supplied methods in Classes



    Hi,


    One way is using reflection mechanism of java 1.1. But you should know the

    class name of class supplied by user. But user Class should also be java class.

    Reflection mechanism is vast and is not quiet conceivable to discuss here.

    Core Java 1.1 Volume-I from sunsoft press, author Cay S. Horstmann and

    Gary C. will of some help.

    Hope this will help.




  3. #3
    Join Date
    May 1999
    Posts
    93

    Re: User Supplied methods in Classes



    You would need to use 'interface'. In Java there is no multiple inheritance and

    no function pointer. Interfaces circumvent the need of MI and also help out where

    we need normally use function pointers in C or C++.


    Define an interface with one (or more) functions. When calling your numeric

    function, you'd have to supply an object that implements this interface.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured