473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I update multiple object references at once?

Hello

I'm working on an application where some common objects are consumed
thorough the application. The issue is that such a common object - say some
kind of graphics object - shall be replaced by another object now and then,
and then all references should be updated at once. Say I reference the same
graphics object ten different places in the application. How can I create a
new graphics object and then make all of the ten references point to this
new object?

Well, I know I could do this by calling a GetNewestGraphicsObject() method
instead of having references directly to the commonly used obejcts. Then
this intermediate method returns the newest object. But is there a way to
achieve this without using methods?
Nov 17 '05 #1
3 1574
"Jocke" <jo***********@home.se> a écrit dans le message de news:
u8**************@TK2MSFTNGP14.phx.gbl...
I'm working on an application where some common objects are consumed
thorough the application. The issue is that such a common object - say some kind of graphics object - shall be replaced by another object now and then, and then all references should be updated at once. Say I reference the same graphics object ten different places in the application. How can I create a new graphics object and then make all of the ten references point to this
new object?

Well, I know I could do this by calling a GetNewestGraphicsObject() method
instead of having references directly to the commonly used obejcts. Then
this intermediate method returns the newest object. But is there a way to
achieve this without using methods?


Take a look at the Observer pattern. The Subject object can change state and
any other objects that are Observers of that Subject will be notified when
the change occurs. The idea of a multicast delegate as used in .NET events
fulfils this pattern perfectly.

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #2
Jocke <jo***********@home.se> wrote:
I'm working on an application where some common objects are consumed
thorough the application. The issue is that such a common object - say some
kind of graphics object - shall be replaced by another object now and then,
and then all references should be updated at once. Say I reference the same
graphics object ten different places in the application. How can I create a
new graphics object and then make all of the ten references point to this
new object?

Well, I know I could do this by calling a GetNewestGraphicsObject() method
instead of having references directly to the commonly used obejcts. Then
this intermediate method returns the newest object. But is there a way to
achieve this without using methods?


Could you actually have an object with the same interface, which just
proxies to whatever the most current real object is? That would be my
first thought as to the best way round it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3

"Jocke" <jo***********@home.se> wrote in message
news:u8**************@TK2MSFTNGP14.phx.gbl...
Hello

I'm working on an application where some common objects are consumed
thorough the application. The issue is that such a common object - say some kind of graphics object - shall be replaced by another object now and then, and then all references should be updated at once. Say I reference the same graphics object ten different places in the application. How can I create a new graphics object and then make all of the ten references point to this
new object?

Well, I know I could do this by calling a GetNewestGraphicsObject() method
instead of having references directly to the commonly used obejcts. Then
this intermediate method returns the newest object. But is there a way to
achieve this without using methods?


Does a "property" count as a "method"?

public class CommonGraphicsObject
{
private static GraphicsObject _currentObject = null;

public static GraphicsObject CurrentObject
{
get { return _currentObject; }
set { _currentObject = value; }
}
}

Then you just reference CommonGraphicsObject.CurrentObject everywhere.

Similar to Joanna's suggestion, you could fire an event in the setter if all
references needed to know when a new object was set.

OTOH, this is very, very similar to calling GetNewestGraphicsObject() -
which you wanted to avoid.
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
3
by: -Michelle- | last post by:
Hi Using A2003 on XP I am wondering from the MVP's and others, what is the most efficient way (in terms of time to process) of updating data in a table, using the docmd.RunSQL or Recordset ...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
30
by: Charles Law | last post by:
Here's one that should probably have the sub-heading "I'm sure I asked this once before, but ...". Two users are both looking at the same data, from a database. One user changes the data and...
3
by: Pieter | last post by:
Hi, I've implemented some type of cache, to be able to point with multiple references to the same object. Although, this 1-object-stuff is broken if I do a refresh from the DataBase. For...
4
by: EnsGabe | last post by:
Suppose you have a class heirarchy as such: class Base{ .... }; class Mid1 : public Base{ ....
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.