which design is better??? in term of memory used, speed...etc????

Discussion in 'Java' started by sayoyo, Jul 7, 2003.

  1. sayoyo

    sayoyo Guest

    Hi Guys,

    I have to implement a design in Java which is a collection class
    gathers several units of the same class.

    I was thinking about two ways to implement it. the first is to create
    two class: the collection class and the unit class. The second one is
    to create only one unit class but, the all units(whole collection) are
    stored into the class variable (static) of the unit class.

    And I have no idea which design is better in term of memory used,
    speed, etc...

    If someone has an idea????? Thanks you very much!!!!!!


    Sayoyo


    class unitSet{
    private HashMap setOfUnit = null;
    unitSet(){
    setOfUnit = new HAshMap(20);
    }
    addUnit()....
    removeUnit()....
    setUnit().....
    }


    class unit{
    unit(){
    }
    }

    ******** OR ***********

    class unit{

    static private HashMap setOfUnit = nll;
    static{
    setOfUnit = new HAshMap(20);
    }
    static addUnit()...
    static removeUnit()...
    static setUnit()...

    unit(){
    }
    }
     
    sayoyo, Jul 7, 2003
    #1
    1. Advertisements

  2. sayoyo

    Jacob Guest

    sayoyo wrote:
    > And I have no idea which design is better in term of memory used,
    > speed, etc...


    Don't care about this. Memory and performance is not
    at stake for the classes mentioned.

    In general: Select the design that is closest to the
    domain objects you are trying to model. In this case
    your first example seems fine.
     
    Jacob, Jul 7, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    512
    John C. Bollinger
    Jun 6, 2005
  2. Andrew Slade

    [OT] - Definition of Usenet term used here a lot

    Andrew Slade, Jan 2, 2004, in forum: C Programming
    Replies:
    10
    Views:
    679
    Andrew Slade
    Jan 3, 2004
  3. Replies:
    9
    Views:
    450
    Jerry Coffin
    Jul 28, 2006
  4. George2
    Replies:
    0
    Views:
    436
    George2
    Apr 12, 2008
  5. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    687
    Fredrik Lundh
    Aug 13, 2008
  6. Nitesh

    Which design in better?

    Nitesh, Aug 25, 2008, in forum: C++
    Replies:
    2
    Views:
    306
    Nitesh
    Aug 26, 2008
  7. Ross
    Replies:
    6
    Views:
    338
    Arne Vajhøj
    Oct 4, 2009
  8. John Goche
    Replies:
    9
    Views:
    935
    Arne Vajhøj
    Dec 3, 2011
Loading...