473,385 Members | 1,930 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,385 software developers and data experts.

Associate Objects using domain ID or using object references?


Hiya
My question is whether or not you should associated related objects in
your software using a scheme of id's and lookups, or wether objects
should actually hold actual object references to objects they are
associated with.

For example, lets say you are modelling studen ratings of teachers.
Let's say your applications needs to analyze these ratings for
teachers and is provided a data file. In this data file the teachers
all have unique id's. Each studen'ts ratings of each teacher is listed
under an appropriate section for each student; these ratings carry the
teacher's ID so that you know what the rating is for.

Now, if you were to model this in software, it seems reasonable that
you might end up with a student class, which directly or indirectly
houses the student's ratings for the the teachers. And you would
probably end up with a teacher class and each teacher object would
carry the id assigned to it in the data file.

The question is this: in the class holding the ratings (e.g., the
student class), would you store ratings along with the teacher's ID or
would you actually store references to the proper teacher object?

On one hand, I like the id scheme because it mimics the domain a bit
more, possibly making the app easier to understand and debug (and
possibly to save off and restore state later? I don't know about this
yet).

On the other hand, if other objects "point to" feature objects by
holding their ID, you will probably have to do a feature-lookup by ID
to get the actual feature object so that you can interact with it.

I thought this issue was addressed by something called the "IDs versus
Objects" pattern, but I can't seem to turn up anything on that.

Any thouhgts on this topic would be greatly appreciated!!

Michael

Sep 21 '07 #1
2 1818
"Veloz" <mi**********@gmail.comwrote in message
news:11*********************@57g2000hsv.googlegrou ps.com...
>
Hiya
My question is whether or not you should associated related objects in
your software using a scheme of id's and lookups, or wether objects
should actually hold actual object references to objects they are
associated with.

For example, lets say you are modelling studen ratings of teachers.
Let's say your applications needs to analyze these ratings for
teachers and is provided a data file. In this data file the teachers
all have unique id's. Each studen'ts ratings of each teacher is listed
under an appropriate section for each student; these ratings carry the
teacher's ID so that you know what the rating is for.

Now, if you were to model this in software, it seems reasonable that
you might end up with a student class, which directly or indirectly
houses the student's ratings for the the teachers. And you would
probably end up with a teacher class and each teacher object would
carry the id assigned to it in the data file.

The question is this: in the class holding the ratings (e.g., the
student class), would you store ratings along with the teacher's ID or
would you actually store references to the proper teacher object?

On one hand, I like the id scheme because it mimics the domain a bit
more, possibly making the app easier to understand and debug (and
possibly to save off and restore state later? I don't know about this
yet).

On the other hand, if other objects "point to" feature objects by
holding their ID, you will probably have to do a feature-lookup by ID
to get the actual feature object so that you can interact with it.

I thought this issue was addressed by something called the "IDs versus
Objects" pattern, but I can't seem to turn up anything on that.

Any thouhgts on this topic would be greatly appreciated!!
If the student object contains the teacher ID, then the teacher ID is not
required to even exist if it is not needed. Also, during serialization you
would not have to be concerned with the teacher object still existing at the
time the student object is output. So in the least the student object needs
to contain the teacher ID whether it is used as a key to the teacher object
or not during lookup.

Using maps a lookup is rather quick and simple to do, so it seems that it
wouldn't be too much of a burden to get a refernce to the teacher object as
needed.

The main concern I see with storing references to a teacher object is the
fact that the teacher object pointer can not then change. If the teacher
object changes in some manner (it's stored by value in a vector and the
vector is resized, sorted, etc...) the reference would become invalid, as I
understand it. Also, there may be a condition where you don't even have the
teacher object loaded and would only load it from DB as needed. If you are
doing this then you have to ensure that the teacher object that was loaded
remains in memory at the same location until the student object is
destructed.

I'm not in favor of storing pointers (or references) to instances in my
classes when it is not strictly needed, and when I do I try to limit them to
objects that are created once at the beginning of the program and are
destructed at the end (graphical engine interface, DB connection info,
etc...).

The problem with not storing a reference, however, now leads us to the
problem of how is the student object going to get access to the teacher
object as needed? But then again, why would the student class ever need
access to the teacher object to begin with? I would not make it the
responsibility of the student class to update the teacher class. I would
lead that responsibilty to either a containing class that kept lists of both
teachers and students, or in mainline.
Sep 21 '07 #2
On Sep 21, 7:10 pm, Veloz <michaelve...@gmail.comwrote:
My question is whether or not you should associated related objects in
your software using a scheme of id's and lookups, or wether objects
should actually hold actual object references to objects they are
associated with.
For example, lets say you are modelling studen ratings of teachers.
Let's say your applications needs to analyze these ratings for
teachers and is provided a data file. In this data file the teachers
all have unique id's. Each studen'ts ratings of each teacher is listed
under an appropriate section for each student; these ratings carry the
teacher's ID so that you know what the rating is for.
Now, if you were to model this in software, it seems reasonable that
you might end up with a student class, which directly or indirectly
houses the student's ratings for the the teachers. And you would
probably end up with a teacher class and each teacher object would
carry the id assigned to it in the data file.
In this simple case, you probably wouldn't even have a teacher
class. Just a teacher ID. You'd only need a teacher class if
the teacher had additional behavior, beyond it's ID.
The question is this: in the class holding the ratings (e.g., the
student class), would you store ratings along with the teacher's ID or
would you actually store references to the proper teacher object?
On one hand, I like the id scheme because it mimics the domain a bit
more, possibly making the app easier to understand and debug (and
possibly to save off and restore state later? I don't know about this
yet).
On the other hand, if other objects "point to" feature objects by
holding their ID, you will probably have to do a feature-lookup by ID
to get the actual feature object so that you can interact with it.
I thought this issue was addressed by something called the "IDs versus
Objects" pattern, but I can't seem to turn up anything on that.
I see what you're getting at, although I don't think your
example shows it. Basically: in memory navigation (from one
object to another) is best handled by pointers; in the end, the
only way you can access another object is if you have its
address in memory. (If you use a table, the result of the table
lookup is a pointer.) Pointers do NOT work for external
communication or persistency, however, or if the objects may
move in memory between transactions (frequently the case, if
e.g. the transaction actually operates on a copy, which is
swapped with the original in the commit phase). So the rule is
to use a pointer if it works, and id's otherwise, and not to
forget that when you do the table lookup, and get the pointer,
you have to lock the object in place as long as you hold the
pointer.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 23 '07 #3

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

Similar topics

9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
3
by: user | last post by:
Say I have an object (foo), that contains an array (bar) of references to other objects. Now I want to puff some of the objects from the array so that I remove the array element, and destroy...
49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
6
by: Bryan Martin | last post by:
I have a object that is created in a seperate domain which needs to be passed back to the parent class. Because this object is created in a seperate domain if I try to pass the object back to the...
9
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
4
by: BD | last post by:
Hi all. Running SQL2K SP4 on W2K3 Standard, SP4. I have just refreshed a database on one server with a backup from another. The database had existed previously on the target server, and I am...
25
by: Penelope Dramas | last post by:
Hello, I'm in a front of very serious .net redesign/rewrite of an old VB6 application. I had been asked to make it .NET 2.0 and would like to ask couple of questions regarding data access as...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.