473,396 Members | 2,030 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,396 software developers and data experts.

Recursive relationships in data objects

I have been working with objects long enough to have the basics down,
but some things give me fits, and this is one of them.

Brief description:
I have an airplane object, and each airplane has an owner.
Likewise I have a customer object and each customer has a list of
airplanes.

The basic structure of my objects is: (ignoring public/private for
clarity)

public class Aircraft
{
int ID;
string Series;
List<Aircraft_OptionsOptionList;
Customer Owner;

/* Assorted Methods */...
}

public class Customer
{
int ID;
string Name;
List<AircraftAircraftList;

/* Assorted Methods */...
}

I want Aircraft to have the Customer object for reference when I grab
the Aircraft List, and obviously when I grab the Customer I want access
to all the associated aircraft. It seems to me I'll run into problems
with recursion. I considered a limited Customer class for Aircraft to
have, but that doesn't strike me as efficient.

How should I best deal with this situation?

Nov 17 '06 #1
4 1877
Since they are classes, recursion isn't really a problem - each can see the
other, but there is still only a fixed number of acutal objects in the
system. It does become an issue e.g. with the XmlSerializer (which can only
serialize object trees, not graphs) - but you can handle that by marking one
direction with [XmlIgnore]. You also now have the issue of which is the
master... but this can also be solved (i.e. changing the customer on the
Aircraft causes it to also go to the Customer and remove itself from the
aircrafts collection, etc).

Memory islands (a common leak in non-GC systems) is not an issue; if the
graph is not visible it gets garbage collected - so you don't have any
exceptional reference-counting to consider.

Was there a specific recursive issue you were thinking of?

Marc
Nov 17 '06 #2
As a direction comparison: compare to winforms; a Control can see it's
parent and it's children; it is actually the exact same scenario, just with
1 base class instead of 2.

Marc
Nov 17 '06 #3
So it's essentially not a problem as long as I am aware of its
structure and be careful with routines that recursively try to list
them.

Awesome! Thanks!

Nov 17 '06 #4
First, you need to be clear whether your Aircraft class represents an
instance of a single Aircraft, or a type of Aircraft, such as a Cessna 195.
If it represents a single Aircraft, then I would assume that there is a
single Owner. If it represents a type of Aircraft, then it would have no
Owner. So, if it is a single Aircraft, you're talking about a one-to-many
relationship of Owners to Aircraft instances. If so, there would be one
Owner per Aircraft, and many Aircraft (o or more) to each Owner. If so,
there is no recursion involved. To find the Owner of a single Aircraft
instance, you look at the Owner property. To find all Aircraft for an Owner,
you look at the AircraftList property of the Owner. Similarly, to find all
Aircraft owned by the Owner of an Aircraft, you look at the AircraftList
property of the Owner property of the Aircraft.

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

Any experience you can walk away from
is a good one.

<li******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>I have been working with objects long enough to have the basics down,
but some things give me fits, and this is one of them.

Brief description:
I have an airplane object, and each airplane has an owner.
Likewise I have a customer object and each customer has a list of
airplanes.

The basic structure of my objects is: (ignoring public/private for
clarity)

public class Aircraft
{
int ID;
string Series;
List<Aircraft_OptionsOptionList;
Customer Owner;

/* Assorted Methods */...
}

public class Customer
{
int ID;
string Name;
List<AircraftAircraftList;

/* Assorted Methods */...
}

I want Aircraft to have the Customer object for reference when I grab
the Aircraft List, and obviously when I grab the Customer I want access
to all the associated aircraft. It seems to me I'll run into problems
with recursion. I considered a limited Customer class for Aircraft to
have, but that doesn't strike me as efficient.

How should I best deal with this situation?

Nov 17 '06 #5

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

Similar topics

5
by: Magnus Lyck? | last post by:
Something really strange is happening to me (sometimes). I'm using Python 2.3.2 on NT 4.0 as well as win32all-157, adodbapi and db_row. During a recursive call to a method, it seems Python...
5
by: Alex Polite | last post by:
I need to put recursive data structures on disc and found out that cPickle doesn't like recursion. What are my options? alex -- Alex Polite http://polite.se
2
by: Perttu Pulkkinen | last post by:
I need to find toplevel image categories and a) number of images directly in them and b) number of subcategories directly in those topcategories. In toplevel image categories "icat_parent_id IS...
20
by: Gary Manigian | last post by:
I have 2 tables, one-to-many, that contain bills of material(BOMs): tblBOM: lngBOMID (PK) strAssemblyPartNo strDescription tblBOMDetail: lngBOMDetailID (PK) lngBOMID (FK)
1
by: a_valued_employee | last post by:
My data model has many tables in many hierarchies. I believe that by using recursion, I can check for all invalid codes in the working tables that do not exist in the code tables. For example, I...
3
by: mizrandir | last post by:
Can someone tell me why python doesn't crash when I do the following: ] ] How does python handle this internally? Will it crash or use up lot's of memory in similar but more complicated cases?
13
by: ARC | last post by:
Hello all, Prior to going live with my app, I have questions on relationships theory. My prior app was done in Access 97, and I did NOT use relationships at all. I have 65 tables in my...
1
by: rekkufa | last post by:
I am currently building a system for serializing python objects to a readable file-format, as well as creating python objects by parsing the same format. It is more or less complete except for a...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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
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...

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.