Results 1 to 5 of 5
  1. #1
    myahia is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default question about coupling in java code

    the the Coupling Corruption Propagation is a OO metric that computed as follows:

    Coupling Corruption Propagation = Number of child methods invoked with the parameters based on the parameters of the original invocation.

    In the code bellow, a parent method calculateStringBuildSpeed invokes a child method called buildString with the parameter length. The method buildString then calls three child methods of its own callStartTime, callEndTime, and reportResult. The methods callStartTim and callEndTime do not take any parameter. Therefore, they are effectively immune to any coupling effects that originate from calculateStringBuildSpeed. However,
    reportResult takes one variable stringLength that is calculated from the original length variable. If the variable is ever compromised (i.e., it becomes null, has a value that exceeds the int range, or contains a value that reportResult cannot use), then reportResult method could indirectly be corrupted from calculateStringBuildSpeed. Therefore, the coupling corruption propagation is 2 in the following code.

    So how can I modify the following code so that the Coupling Corruption Propagation will decrease for example into 1 or 0

    -------------------------------------------------

    Public void CalculateStringBuildSpeed(double
    numOfElements)
    {
    buildString (numOfElements);
    }
    .
    .
    .
    public String buildString(double length) {
    String result = "";
    int startTime;
    int endTime;
    int stringLength = (int) length;
    startTime = callStartTime();
    System.out.println("Starting Now");
    for (int i = 0; i < stringLength; i++) {
    result += (char)(i%26 + 'a');
    }
    endTime = callEndTime();
    reportResult(startTime,endTime,stringLength);
    return result;
    }

    ---------------------------------------------------------

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default Re: question about coupling in java code

    Also posted at: Coupling in Java Code
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,807
    Rep Power
    5

    Default Re: question about coupling in java code

    If I understand your question, it would seem to me that enforcing invariants on the parameters and using immutable objects or making defensive copies of mutable objects would help solve your problem.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    myahia is offline Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    Default Re: question about coupling in java code

    but if you would please apply what you say to the following code (i.e. up[dating the code) so when I compute the Coupling Corruption Propagation I will get 1 or 0

    Java Code:
    Public void CalculateStringBuildSpeed(double numOfElements)
    {
        buildString (numOfElements);
    }
    .
    .
    .
    public String buildString(double length) {
       String result = "";
       int startTime;
       int endTime;
       int stringLength = (int) length;
       startTime = callStartTime();
       System.out.println("Starting Now");
       for (int i = 0; i < stringLength; i++) {
          result += (char)(i%26 + 'a');
       }
       endTime = callEndTime();
       reportResult(startTime,endTime,stringLength);
       return result;
    }

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default Re: question about coupling in java code

    Um, no.
    That's not how this works.
    We make suggestions and you implement them.
    That way we know you've actually understood the suggestion and are not simply copy/pasting.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. I have a question regarding a simple code in JAVA
    By yakirbu in forum New To Java
    Replies: 14
    Last Post: 04-21-2014, 05:35 PM
  2. Replies: 3
    Last Post: 01-13-2012, 12:45 PM
  3. Question on the speed of c code when called from Java
    By Steven Miller in forum Advanced Java
    Replies: 5
    Last Post: 02-08-2011, 11:41 PM
  4. need a java code for this question!
    By rose in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:34 PM
  5. coupling
    By srinuvericharla in forum Advanced Java
    Replies: 1
    Last Post: 05-16-2007, 05:06 PM

Posting Permissions

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