473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Transfer of Integer!

2
Hello guys......I have a problem with my code, its more like I am stuck to continue further if I cannot find a way or an alternative.
The problem is I have an integer X in a class called
Langkawi, and I want the same integer to be present in another class
called 'SA'.
In this way, as int X changes in Langkawi class, changes will apply to
int X in SA class as well. Just like the Paste special in MS
Excel. I would be grateful to anyone who comes to the rescue because my due date is closing in very fast...:-)
Nov 27 '09 #1
3 1752
pbrockway2
151 Expert 100+
It's hard to say without knowing what you are trying to do (as distinct from how you are trying to do it).

a) The instance of Langkawi which has the variable x of interest could be given a reference to the instance of SA that should know about changes of value. Have all changes to x occur through a "mutator" method (setX()) which calls some method of SA to notify it of the change.

a2) Make x a bound property of Langkawi.

b) The instance of SA that is to use the value of the variable x could have a reference to the instance of Langkawi which has the value. The SA instance should use an "accessor" method (getX()) whenever it wants the value.

c) The design could be changed so that SA no longer depends so strongly on Langkawi. Whatever behaviour it is that SA wants could be expressed as an interface that Langkawi implements. As in (b) the SA instance is given a reference to the Langkawi instance of interest (now as an instance of the interface). Whenever the SA instance wants the behaviour to occur it doesn't ask the Langkawi instance what its x value is, but tells it to perform the desired behaviour.
Nov 27 '09 #2
KRAZY
2
Hey pbrockway2!
Thanks for the knowledge; I appreciate your help on this one, atleast I got a headway on how to go about it. Let me apply the steps and see what I shall foster from it; in case of any problems, I ought to know what to do from here on.

Once again, my sincere gratitude yooooo! Peace
Nov 28 '09 #3
pbrockway2
151 Expert 100+
You're welcome. Notice that the methods listed are alternatives not a sequence of steps to be performed...

Anyway here's an example (of (b)):

Expand|Select|Wrap|Line Numbers
  1. class Sky {
  2.         // Sky has an integer value as a field.  This value may change.
  3.     private int color;
  4.  
  5.     public void setColor(int c) {
  6.         color = c;
  7.     }
  8.  
  9.     public int getColor() {
  10.         return color;
  11.     }
  12. }
  13.  
  14.     // Instances of Place want to be able to access the integer value
  15.     // of a particular Sky instance.  And they always want the current
  16.     // value
  17. class Place {
  18.     private String name;
  19.     private Sky sky;
  20.  
  21.         // In the Place constructor each instance is given a reference to
  22.         // an instance of Sky.
  23.     public Place(String name, Sky sky) {
  24.         this.name = name;
  25.         this.sky = sky;
  26.     }
  27.  
  28.         // The Place instance will use an "accessor" method - getColor() -
  29.         // every time it wants the sky colour
  30.     public void report() {
  31.         System.out.printf("At %s the sky is %h.%n", name, sky.getColor());
  32.     }
  33. }
  34.  
  35. public class SharedIntEg {
  36.     public static void main(String[] args) {
  37.         Sky sky = new Sky();
  38.         sky.setColor(0x4545FF);
  39.  
  40.         Place place = new Place("Somewhere", sky);
  41.         place.report();
  42.  
  43.         // Now let's change the sky's colour and see what the
  44.         // place reports.
  45.  
  46.         sky.setColor(0x333333);
  47.         place.report();
  48.     }
  49. }
  50.  
Nov 28 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Eric Cory | last post by:
Hello Gurus I can't get Dart PowerFTP to do anything. I create the ftp oblect and set the connection values, but when I do a get, put or even an invoke for a site command, I always get the...
2
by: David Berman | last post by:
It seems that my site is losing session information when using Server.Transfer. I have a page called PictureGallery.aspx. It takes an argument which is an index id, so it would look like...
4
by: Sparky Arbuckle | last post by:
I want to transfer to a search page from my default page to SearchResults.aspx and I want to pass a variable named strSearch. So far I have: Dim strSearch as string strSearch = tbSearch.text...
4
by: Fernando Lopes | last post by:
Hi there. There's a way to transfer data between pages but: - Not using Session - Not use Querystring Tks. Fernando Lopes
1
by: steellock | last post by:
The below code always get compile error, "Can not change Interger to UInt32". Then How to set the BackColor property With TextObjec .Name = "txtProductCode .SetText("Apple" .BackColor = 8 '...
2
by: Bonzol | last post by:
vb.net 2003 Windows application We have a Client/Server system set up by communicating through a TCPClient object. The server loops continuously using a tcplistener device and each time a client...
2
by: rajaaryan44 | last post by:
how can we transfer data from one access database to another databse . the table name is same for both the database . in one table some records are there (rs say e.g.) now another table has say rs+10...
0
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally...
0
by: peridian | last post by:
Hi, I have the below code to transfer code modules between Access database files. I have three problems, only one of which is annoying. a) How do you prevent the Save As box from appearing...
4
by: Andrew Jackson | last post by:
I am writing a newsgroup client. I have the protocol figured out. But I get slow transfer speeds off any of the network objects read the data from For example one of the commands for a news...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.