Results 1 to 2 of 2
  1. #1
    jezza10181 is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default Use a 'nested class' here?


    I have written a class called 'Matrix', which as the name implies, is an implementation of the mathematical concept of a matrix (this being a 2 dimensional array of numbers).

    There is something called an 'LU decomposition' in matrix theory, that takes a matrix, and 'decomposes' it in to two other matrices, called the 'L' and the 'U' matrices.

    Now, as one of the methods for the 'Matrix' class, I have written one that performs an 'LU decomposition'. Clearly, this has to return two items - the L and the U matrices.

    As Java only allows methods to return one return type, then I've resorted to tagging the matrices to a List and then to return the list. But, I've thought of a better way, and that is to create a 'nested class' called 'LUdecomposition' within the Matrix class, and then to simply only have a constructor within that class, and then to have the Lmatrix and Umatrix as arguments.

    The luDecomposition method would then simply return an instance of this nested class as a return type.

    Would you say this is a good way to approach this? Any better suggestions?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Why not make the LUDecomposition class a separate class? There is no need to make it a nested class of the Matrix class. Also note that all elements on the diagonal of the L matrix are 1 (one) so there's no need to store them explicitly. That way you can pack both the L and U matrixes in one square Matrix.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Nested Loops
    By candygirl198827 in forum New To Java
    Replies: 38
    Last Post: 12-01-2010, 06:03 AM
  2. Nested List class for Simulation Queue
    By Cheddz in forum Advanced Java
    Replies: 2
    Last Post: 02-19-2010, 01:19 AM
  3. can some one help me with nested loop?
    By keycoffee in forum New To Java
    Replies: 10
    Last Post: 01-25-2010, 02:49 AM
  4. Nested Classes
    By new.guy in forum New To Java
    Replies: 13
    Last Post: 09-07-2008, 04:44 AM
  5. Nested For Loop
    By yuchuang in forum New To Java
    Replies: 1
    Last Post: 07-08-2007, 01:11 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