Solved

Java Vector quesion

Posted on 2011-09-07
8
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

739 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