found the solution. Sorry for disturbing:)
> hi ,
>
[quoted text clipped - 5 lines]
>
> Thanks!
> hi ,
>
[quoted text clipped - 5 lines]
>
> Thanks!
whilst its certainly possible (google 'instanceof') its not usually a
good design choice to mix the value types within a collection.
Preferably, have two collections, one for the Integers one for the Strings.
If this is not possible, write a simple data holder class which you can
store both Integer and String inside it, and add an instance of this
dataholder into the collection.
class DataHolder {
public Integer intValue;
public String stringValue;
}
....
map.put(key, dataHolder);
Doing this will be a good start along a design path where very quickly
you find that the dataHolder class needs to have some instance methods
too - it becomes a proper class with its own responsibilities.
A contrived example...
renaming DataHolder to 'Address' and the member vars to houseNumber &
streetName, starts to show that those vars mean something.
class Address {
public Integer houseNumber;
public String streetName;
}
Then we might find that Address should be able to save/update its own
values by setting/getting them from a db...
class Address {
public Integer houseNumber;
public String streetName;
public void refresh() {
houseNumber = db.getHouseNumber();
streetName = db.getStreetName;
}
}
HTH
Andrew
hyena - 15 Dec 2005 13:14 GMT
Thanks, Andrew,
Actually I was just doing sonthing in a fast and dirty way:). Just have
forgotten the instanceof operator when I ask the question.
Anyway, thanks for your example, it is clearly better then the messy
approach I am using now.
>> hi ,
>>
[quoted text clipped - 59 lines]
>
> Andrew
Andrew McDonagh - 15 Dec 2005 13:48 GMT
> Thanks, Andrew,
>
[quoted text clipped - 5 lines]
>
> "Andrew McDonagh" <news@andrewcdonagh.f2s.com> wrote in message
no prob =- glad to help
isamura - 15 Dec 2005 16:22 GMT
: Thanks, Andrew,
:
[quoted text clipped - 3 lines]
: Anyway, thanks for your example, it is clearly better then the messy
: approach I am using now.
Andrew's example demonstrates good OOP.
It goes to show one does not necessary do OO just because the underlying programming language is
one. The concepts need to be learned and applied consistently.
.k