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

    Default Use a 'nested class' here?

    Hi,

    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 online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default

    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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
  •