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

S

sayoyo

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(){
}
}
 
J

Jacob

sayoyo said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top