Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > reference objects (newbie question)

Reply
Thread Tools

reference objects (newbie question)

 
 
Roderik
Guest
Posts: n/a
 
      11-28-2003
Hi,

I'd like to make a function to manipulate objects of a given class.

Let's say there are two objects, called MyPoint1 and MyPoint2.
They are both of the class cCustomPoint and contain an x an y
attribute.

The function should assign a value for x to a passed object (MyPoint1
or MyPoint2).

How should I make this function so it knows which object to manipulate
and the value to be assigned?

Kind regards,

Roderik
 
Reply With Quote
 
 
 
 
Anthony Borla
Guest
Posts: n/a
 
      11-28-2003

"Roderik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I'd like to make a function to manipulate objects of a
> given class.
>
> Let's say there are two objects, called MyPoint1
> and MyPoint2. They are both of the class
> cCustomPoint and contain an x an y attribute.
>
> The function should assign a value for x to a passed
> object (MyPoint1 or MyPoint2).
>


class cCustomPoint
{
public int getX() { return x; }
public int getY() { return y; }
public int setX(int x) { this.x = x; }
public int setY(int y) { this.y = y; }

private int x, y;
}

class cCustomPointManager
{
...
public void passXTocCustomPoint(int x, cCustomPoint ccp)
{
ccp.setX(x);
}
...
}

...
public static void main(String[] args)
{
...
cCustomPointManager ccpm = new cCustomPointManager();
...
cCustomPoint MyPoint1 = new ..., MyPoint2 = new ...;
...
...
ccpm.passXTocCustomPoint(5, MyPoint1);
ccpm.passXTocCustomPoint(6, MyPoint2);
...
...

>
> How should I make this function so it knows which
> object to manipulate and the value to be assigned?
>


I'm not sure what you are asking here. As the sample code [a very contrived
example at that] shows, you normally know which object you want manipulated
when you pass it as an argument to a method.

I hope this helps [though you may need to rephrase your question]

Anthony Borla


 
Reply With Quote
 
 
 
 
Jose Rubio
Guest
Posts: n/a
 
      11-28-2003
Something like

manipulate( cCustomPoint aPoint )
{
aPoint.setX( whatever );

etc. etc. etc.
}

So you would call this method passing the object you want like this:

manipulate( MyPoint1 );

--
Jose Rubio
Lead Consultant
Airphoria
http://www.airphoria.com


"Roderik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I'd like to make a function to manipulate objects of a given class.
>
> Let's say there are two objects, called MyPoint1 and MyPoint2.
> They are both of the class cCustomPoint and contain an x an y
> attribute.
>
> The function should assign a value for x to a passed object (MyPoint1
> or MyPoint2).
>
> How should I make this function so it knows which object to manipulate
> and the value to be assigned?
>
> Kind regards,
>
> Roderik



 
Reply With Quote
 
Roderik
Guest
Posts: n/a
 
      11-28-2003
On Fri, 28 Nov 2003 21:04:56 GMT, "Anthony Borla"
<(E-Mail Removed)> wrote:

>
>"Roderik" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> Hi,
>>
>> I'd like to make a function to manipulate objects of a
>> given class.
>>
>> Let's say there are two objects, called MyPoint1
>> and MyPoint2. They are both of the class
>> cCustomPoint and contain an x an y attribute.
>>
>> The function should assign a value for x to a passed
>> object (MyPoint1 or MyPoint2).
>>

>
> class cCustomPoint
> {
> public int getX() { return x; }
> public int getY() { return y; }
> public int setX(int x) { this.x = x; }
> public int setY(int y) { this.y = y; }
>
> private int x, y;
> }
>
> class cCustomPointManager
> {
> ...
> public void passXTocCustomPoint(int x, cCustomPoint ccp)
> {
> ccp.setX(x);
> }
> ...
> }
>
> ...
> public static void main(String[] args)
> {
> ...
> cCustomPointManager ccpm = new cCustomPointManager();
> ...
> cCustomPoint MyPoint1 = new ..., MyPoint2 = new ...;
> ...
> ...
> ccpm.passXTocCustomPoint(5, MyPoint1);
> ccpm.passXTocCustomPoint(6, MyPoint2);
> ...
> ...
>
>>
>> How should I make this function so it knows which
>> object to manipulate and the value to be assigned?
>>

>
>I'm not sure what you are asking here. As the sample code [a very contrived
>example at that] shows, you normally know which object you want manipulated
>when you pass it as an argument to a method.
>
>I hope this helps [though you may need to rephrase your question]
>
>Anthony Borla
>


Yes, this is okay.

thanks a lot.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
form objects into class objects =?Utf-8?B?c3RldmVuIHNjYWlmZQ==?= ASP .Net 1 07-06-2006 08:33 AM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
Inheritance of objects within objects Simon Elliott C++ 2 12-10-2004 10:59 AM
objects of objects, vectors and sessions bigbinc Java 3 11-18-2003 09:26 AM



Advertisments