java - avoiding class creation while making use of polymorphism -


I do not really have very practical experience with Java or above, so now I have a problem that could actually work It's easy, but where I'm not sure what an elegant, top-oriented solution might look like.

So here's a simple raddin:

I want to write some type of calculation app, which includes the first of many ways: < [...] Fixed double cosine (double x) {...}

and even further. Some other static method would then calculate some kind of derivatives that would include the derivative of one of these tasks. If we pretend that there was no way to estimate derivatives, then the easiest solution for me was one way for me to wrap each method above in the classroom and apply those interfaces 'debrevibal' to those classes. Called 'evaluation evaluation', for example:

  Interface Differential (double evaluation) directive (double X); } Class Signable (Stable Double Assessment) (Double X) {Return ...; } Evaluation of public double evaluation (double X) {return cosine.evaluate (x); }}   

So if I need to get a derivative for any other method, then I can do something like this:

  Static Double Returns DerivativePlusOne ( Debrecive D, Double X) {Return d.evaluateDerivative (x) + 1; OK, now the problem is: When I really want to call the above method, I want an example of sign class like:  
 < Code> derived plusone (new sign (), 1);   

That really does not make sense because there are only static methods (and probably some final fields) in the sign class, so making an object makes me feel weird.

, is there a different approach that will give the same results in the same magnificent manner? Any help would be appreciated.

Why not use evaluation function is still static. There is no need for the interface.

To use polymorphism, we can do the following. Suppose we are doing the following: We have two classes sign and cosine, and are responsible for an interface. Interactive Differential Interface (Double X);} Class Sign Executionable {Fixed Double Evaluation (Double X) {return ...} Evaluation of Public Double Assessment (Double X) } {Return somevalue;}} class cosine perceptual applied (constant double evaluation (double x) {return ...} In that case, to use polymorphism, what you can do:

 < code> public double evaluation current (double x) {return somevalue;}}   

decommissioning D = new sign (); dual-derived = D. evaluation divert (); d = new cosine (); derived = d.evaluateDerivate ();

Hope this helps.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -