Solved

Java Vector quesion

Posted on 2011-09-07
8
246 Views
Last Modified: 2012-05-12
I am creating a class that extends Vector. The vector will consists of 4 elements in this order:
String, String, Date, double

How do I set this up?
0
Comment
Question by:allelopath
8 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 36499373
>>I am creating a class that extends Vector.

Why? ;)
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499375
I don't think you need to extend Vector

You rather make a class


public class  FourElements {
String one;
AString two;
Date d;
double x;

}


then you want constructor etc.

and then you make Vectorb which would hole ielements - each one ionstance of your class




}
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36499381
Or you can have class which will have Vectopr with your four element as
varaiable so it will be not inheritance but

HAS a Vector

relationship
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 47

Expert Comment

by:for_yan
ID: 36499384
It is hard to imagine situation where you want to extend Vector
0
 
LVL 47

Accepted Solution

by:
for_yan earned 300 total points
ID: 36499828
seee here a rather good discussion which comes to the conclusin that it is normally not a good
idea to extend Vector:

http://forums.whirlpool.net.au/archive/1309754



The author of this code [whic was extending Vector, see link above] was probably thinking something along the lines of "a product catalog is a kind of vector, since it stores a bunch of products, just like a vector stores a bunch of items".

The "is a kind of" relation is most often represented with inheritance.

Unfortunately, the author of this code made the wrong decision. A product catalog is not a kind of vector:

    A product catalog doesn't necessarily entail a particular ordering between its entries; a vector does.
    A product catalog has certain rules and constraints about its entries, such as that every element must be a Product, and that the catalog should only be modified in ways that maintain these constraints. A vector doesn't have these rules and constraints.

For these reasons, this ProductCatalog class does not meet the second requirement in my previous post.

At another level, it's a wrong design decision because they're locking in the implementation of their product catalog in such a way that it'd be particularly hard to change in the future.

Even if it is thought that it will not need to be changed in the future, it's the wrong data structure anyhow: a product catalog would probably need to be searched with a variety of different criteria (e.g. by product type, by price, by colour), and a single vector does not make this straight-forward.
0
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 100 total points
ID: 36504603
Also, its generally much better to use one of the other List implementations than Vector -- using the utilities in java.util.concurrent if you need synchronized access to the List.  Vector does a lot of internal synchronization which makes it much slower when only accessed by a single thread.
0
 
LVL 1

Author Comment

by:allelopath
ID: 36511220
ok, it was a stupid idea, driven by a DefaultTableModel constructor :
DefaultTableModel(Vector data, Vector columnNames)
but still not a good way to go.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36511564
>>ok, it was a stupid idea, driven by a DefaultTableModel constructor :

If you'd answered my question and told me that right away, i would have answered differently - and differently from any of the other answers above ;)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question