How to implement Data Structure with custom methods

Hello all

im not sure if the topic is right but what im trying to do is goes like this :

i have Custom Data Structure this custom data structure have basic methods and have no logic

some thing like this :

publicclass MyStruct{

protectedint i ;

protected String j ;

public MyStruct(){

this.i = 0;

this.j =null;

}

publicvoid getID(int i){

this.i = i;

}

publicvoid getID(String i){

this.j = i;

}

}

now say i like to add some logic and some methods to this data structure

BUT ( and here is my problem ) i like to make this addition plug ( i have no other way to describe it )

that is add some kind of class that will extend this class and will add me more possibilities to my data Structures

here im extending the MyStructMethod_1 with MyStruct class but i know its not the right way do to it i just dont know

how to do it , so i have this:

publicclass MyStructMethod_1extends MyStruct{

publicvoid getID(int ii,int jj){

i = ii*jj;

}

publicvoid getID(String ii ,String jj){

j = i+j;

}

}

and from my Main code i could

refer to my MyStruct like this ( again i know it will not work its only so show what i mean )

MyStruct ms = new MyStruct();

ms.getID(2,3);

ms.getID("hello","world");

ms.getID(5);

as you can see im referring to my MyStruct with the methods i defined in the sub class

then i could make many plugble subclass that will extend my MyStruct .

can it be done in java ?

thanks allot

[2810 byte] By [Meirya] at [2007-10-3 9:51:05]
# 1

That isn't what inheritence is for.

An "object" represents a conceptual entity which has behavior and data.

Your description is that you want behavior to act on data - which isn't the same thing.

Just create some classes with no data (behavior only) and pass the data only structure to the methods of those classes.

jschella at 2007-7-15 5:08:22 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
hello and thanks for the fast reply can you please give some kind of simple example so i could understand it better thanks allot
Meirya at 2007-7-15 5:08:22 > top of Java-index,Other Topics,Patterns & OO Design...
# 3

i will try to explain my self again ( English is not my native luggage also ...)

my porpoise is to separate the methods and the logic from my main Data Structure

i will like to have main class that is MyStruct , and every where from my code i will

refers to this data structure as "MyStruct " not something else

BUT here is my main problem .. i need to find away to add or substract methods from this class . not extend from it

using inheritance . with additinal class's .

here is another scenario :

say i have application that uses my Data Structure now this application can interact with different applications

so if my application interact with application A1 every where in application A1 code they will use "MyStruct" Data Structure

with methods that are relevant only to application A1 and these methods need to sit on some class that some how extends "MyStruct"

this can be with application B1 , C1 and so on and every where it will be referred as "MyStruct" not something else as the class that extends it .

i hope i made my self clear now .

thanks

Meirya at 2007-7-15 5:08:22 > top of Java-index,Other Topics,Patterns & OO Design...