?
Solved

Java Vector quesion

Posted on 2011-09-07
8
Medium Priority
?
250 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1200 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 400 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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 This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month8 days, 4 hours left to enroll

765 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