Groups | Search | Server Info | Login | Register


Groups > comp.sources.d > #91

Good pattern for realizing the out-param capability in Java?

X-Received by 10.157.45.54 with SMTP id v51mr2576017ota.45.1473870105755; Wed, 14 Sep 2016 09:21:45 -0700 (PDT)
X-Received by 10.157.4.137 with SMTP id 9mr262022otm.3.1473870105660; Wed, 14 Sep 2016 09:21:45 -0700 (PDT)
Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!u18no213259ita.0!news-out.google.com!w143ni1068itb.0!nntp.google.com!u18no213254ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.sources.d
Date Wed, 14 Sep 2016 09:21:45 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=71.240.181.252; posting-account=4DogHwoAAACcnQyUIXIIpmNFupyYV-Fk
NNTP-Posting-Host 71.240.181.252
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <46744385-abf5-4bde-967b-352e6b17042d@googlegroups.com> (permalink)
Subject Good pattern for realizing the out-param capability in Java?
From sandeep6699@yahoo.com
Injection-Date Wed, 14 Sep 2016 16:21:45 +0000
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Lines 46
Xref csiph.com comp.sources.d:91

Show key headers only | View raw


I want to solicit the opinion of the Java experts about realizing the out-param capability in Java.  Suppose there is a method in a class where I would like to realize the following:

class MyClass {
    int myMethod(int inIntParam, int outIntParam, double outDoubleParam) {
        // Accepts inIntParam as input
        // Updates outIntParam and outDoubleParam
        // Returns an int
        …
    }
    …
}

Since primitive types are passed by values, and primitive type wrapper classes are immutable, I am thinking of having outIntParam and outDoubleParam as instance variables in the class, which get set prior to calling myMethod.  Then myMethod can make do with only one parameter i.e. 

class MyClass {
    protected int outIntParam;
    protected double outDoubleParam;

    int getOutIntParam() {
        return outIntParam;
    }

    double getOutDoubleParam() {
        return outDoubleParam;
    }
    // 
    // And Settors for these instance variables
    // …

    int myMethod(int inIntParam) {
        // Accepts inIntParam as input
        // Updates instance variables in outIntParam and outDoubleParam
        // Returns an int
    …
    }
    …
}

Kindly suggest if there is a preferred way to realize the same.

Regards,
Sandeep

Back to comp.sources.d | Previous | Next | Find similar


Thread

Good pattern for realizing the out-param capability in Java? sandeep6699@yahoo.com - 2016-09-14 09:21 -0700

csiph-web