473,548 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there an interface to replace Vector?


I have a class extending Vector, but I want it to extend another base class
that contains variables. Can I implement some interfaces to do the same
thing?

The following from the Vector API makes me think I'm out of luck:

public class Vector
extends AbstractList
implements List, Cloneable, Serializable

But I would appreciate another opinion.

Assuming I'm right, is this a feature or a flaw of Java?

Thanks,
Peter.
Jul 17 '05 #1
1 2936
Hi Peter,

Is it an idea to write a "Wrapper" class that contains the Vector (or other
base class) then write your own methods to put and get the variables.

Something like:

public class WrapperClass (BaseClass base)
{
private BaseClass privateBaseClas s;

public Iterator getIterator()
{
Your code to return an Iterator;
}

public ArrayList getArryList()
{
Your code to return an ArrayList;
}

public Object getObject(Objec t key)
{
Your code to return the object belonging to key
}

......... etc ........

public WrapperClass(Ba seClass base)
{
privateWrapperC lass = base;
}

}

Then use it like:
WrapperClass wrapped = new WrapperClass(<y our base class object>)

for (Iterator i = wrapped.getIter ator(); i.hasNext();)
{
Do your stuff......
}

Hope it gives you ideas.....

Regards,

Frank.

"Peter Chatterton" <pe***@chattert on.name> wrote in message
news:8X******** **********@news 20.bellglobal.c om...

I have a class extending Vector, but I want it to extend another base class that contains variables. Can I implement some interfaces to do the same
thing?

The following from the Vector API makes me think I'm out of luck:

public class Vector
extends AbstractList
implements List, Cloneable, Serializable

But I would appreciate another opinion.

Assuming I'm right, is this a feature or a flaw of Java?

Thanks,
Peter.

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1897
by: Pierre Barbier de Reuille | last post by:
Ok, I first want to stress that I looked through the newsgroups archives (on Google) for an answer to my question, but I didn't find it. It's about the interface of the set classes as defined in the PEP 218. I don't understand why the sets has an interface of mapping object without associated value and not an interface of sequence ? For...
3
3586
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would be "public interface Value{}" in Java! class IntValue : public Value{ private: int _value; public:
1
2515
by: sandeep Kanwal | last post by:
Hello, Just started using some STL stuff and I am getting some compiler error as below Please guide... Error : illegal operands 'GraphicDataLinkInfo' == 'const GraphicDataLinkInfo' (point of instantiation: 'main()') (instantiating: 'std::replace<std::__wrap_iterator<std::vector<GraphicDataLinkInfo,...
3
5446
by: bonj | last post by:
Hello How do I declare a template class such that the template class T must implement a certain interface? e.g. interface IProvideID { int MyID; };
8
5016
by: He Shiming | last post by:
Hi, I've developed a class that implements an interface definition. It looks like this: class IRecord { public: // define interface methods by pure virtual methods // no member variables }
8
3932
by: Gregory | last post by:
I have a question about using STL containers in C++ class public interface. Lets say that I want to return some container from class method or accept class method parameter as some container. For example: class A { public: const vector<int>& getTable() { return m_table; }
2
2154
by: brutus | last post by:
Hi, I'm trying to define a map-like interface to a container. My basic problem is that the container is associative, but values are not stored in pairs internally. (and as we know, the map value_type must be pair<const Key, T>) Instead there's a list (vector) of values, and a method to get key reference.
7
3123
stealwings
by: stealwings | last post by:
I have a little problem with my program, or maybe it is not that little, anyway here is the code: #include "stdafx.h" #include <iostream> using namespace std; #include <fstream> using std::ifstream; using std::ofstream; #include <stdio.h> #include <cstdlib> #include <string>
0
1231
by: vaclavpich | last post by:
Hi all, I needed a priority queue but I couldn't use stl. So I wrote my priority queue. But I'm not sure that my implementation is good. I want to know your opinion : ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1) template< class _Ty, class...
0
7512
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3495
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.