Question about visibility/ modifications of objects

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I´ve a general question about the visibility and modification of an object.

I will try to explain it in my code, where I have the problem:


DocumentList dList = initDocuments(thesaurus);

for (int i = 0; i < testRuns_; i++)
{
Algo algo = new Algo(dList, 1.1, anzahlCluster, thesaurus, initType_);
run = algo.run(maxIter, epsilon);
tests.add(i, run);
}


In my DocumentList dList I have a List of objects which I create with
initDocuments().

In the for-loop I am removing some objects (documents) out of the
DocumentList with my method algo.run.

Let´s say my DocumentList has a size of 100 _before_ entering the loop.
If I call algo.run, I am removing 4 Documents out of my DocumentList.
So I have 96 Documents in my list.

But I thought, that I am removing these documents _only_ in my object
"Algo" and not in my object dList which I have created _before_ entering
the for-loop.

In other words:

I want to have 100 Documents in my DocumentList.
Then I am doing the first loop iteration, removing 4 but when I am doing
my second iteration, I want to have 100 Documents again and not 96.


But that is exactly what happens.

If I run my loop a second time, I only have 96 Documents and not 100
Documents.


Well.. I hope I explained it right and somebody understands my problem.

My general question is about visibility and modifications of objects.
How can I reach that my object "algo" does not change my object "dList"?
In other words... the object "algo" should work with it´s own copy of
the object dList.


Regards,

Martin
 
Hello,

I´ve a general question about the visibility and modification of an object.

I will try to explain it in my code, where I have the problem:

DocumentList dList = initDocuments(thesaurus);

for (int i = 0; i < testRuns_; i++)
{
Algo algo = new Algo(dList, 1.1, anzahlCluster, thesaurus, initType_);
run = algo.run(maxIter, epsilon);
tests.add(i, run);

}

In my DocumentList dList I have a List of objects which I create with
initDocuments().

In the for-loop I am removing some objects (documents) out of the
DocumentList with my method algo.run.

Let´s say my DocumentList has a size of 100 _before_ entering the loop.
If I call algo.run, I am removing 4 Documents out of my DocumentList.
So I have 96 Documents in my list.

But I thought, that I am removing these documents _only_ in my object
"Algo" and not in my object dList which I have created _before_ entering
the for-loop.

In other words:

I want to have 100 Documents in my DocumentList.
Then I am doing the first loop iteration, removing 4 but when I am doing
my second iteration, I want to have 100 Documents again and not 96.

But that is exactly what happens.

If I run my loop a second time, I only have 96 Documents and not 100
Documents.

Well.. I hope I explained it right and somebody understands my problem.

My general question is about visibility and modifications of objects.
How can I reach that my object "algo" does not change my object "dList"?
In other words... the object "algo" should work with it´s own copy of
the object dList.

Regards,

Martin

I think your problem might be in the Constructor for Algo. When you
assign the values of dList to I guess a local dList in the Algo
instance do you assign just the values? Please post the Constructor
and any other needs methods in the Algo class.
 
justin said:
I think your problem might be in the Constructor for Algo. When you
assign the values of dList to I guess a local dList in the Algo
instance do you assign just the values? Please post the Constructor
and any other needs methods in the Algo class.

Here is the Constructor:

private DocumentList dList_;

public A.go(DocumentList dList, double fuzzyness /*...*/)
{
logger_.Info("Initialisiere...);
dList_ = dList;
//...
}

I do not understand it. Remember:

DocumentList dList = initDocuments(thesaurus);

for (int i = 0; i < testRuns_; i++)
{
Algo algo = new Algo(dList, 1.1, anzahlCluster, thesaurus, initType_);
run = algo.run(maxIter, epsilon);
tests.add(i, run);
}

In every iteration I am creating a _new_ object "algo" with a _new_
Constructor.

So I do not understand why I have the changes of my DocumentList made by
algo in iteration 1 in my next algo in iteration 2.

How could it be?



Regards,

Martin
 
justin creasy schrieb:




Here is the Constructor:

private DocumentList dList_;

public A.go(DocumentList dList, double fuzzyness /*...*/)
{
logger_.Info("Initialisiere...);
dList_ = dList;
//...

}

I do not understand it. Remember:

DocumentList dList = initDocuments(thesaurus);

for (int i = 0; i < testRuns_; i++)
{
Algo algo = new Algo(dList, 1.1, anzahlCluster, thesaurus, initType_);
run = algo.run(maxIter, epsilon);
tests.add(i, run);

}

In every iteration I am creating a _new_ object "algo" with a _new_
Constructor.

So I do not understand why I have the changes of my DocumentList made by
algo in iteration 1 in my next algo in iteration 2.

How could it be?

Regards,

Martin

I am not very familiar with the DocumentList control but it sounds
like when you write

dList_ = dList;

it is copying a reference to dList, not the values of everything in
dList. Read this MSDN article on how to use the DocumentList and see
if it helps. Also look around to find out if DocumentList is passed as
reference or value.

http://msdn2.microsoft.com/en-us/library/ms172535.aspx
 
justin said:
I am not very familiar with the DocumentList control but it sounds
like when you write

dList_ = dList;

it is copying a reference to dList, not the values of everything in
dList. Read this MSDN article on how to use the DocumentList and see
if it helps. Also look around to find out if DocumentList is passed as
reference or value.

http://msdn2.microsoft.com/en-us/library/ms172535.aspx

LOL! Sorry please. I am not using the DocumentList control!

The class DocumentList I wrote by myself.
It´s a subclass of ArrayList and manages my Document objects:

public class DocumentList : ArrayList
{
public new Document this[int index]
{
get { return (Document)base[index]; }
}

public override int Add(object document)
{
return base.Add(document as Document);
}
}


So how can I find out if it is call by reference or call by value?


Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top