.NETGURU
Collection of Objects
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


Jon Ceanfaglione
I have two objects, let's say person and address. I want to allow person
objects to have multiple addresses. What is the best way to accomplish
this? I would think to create a collection of address objects that is
exposed as a property of the person object. I'm thinking something like the
following:

Person _Person = null;
Address _Address = null;

_Person = new Person();
_Person.Name = "John Doe";
_Person.BirthDate = "11/10/1969";

_Address = new Address();
_Address.Street = "100 Main Street";
_Address.City = "Erie";
_Address.State = "IN";
_Address.Zip = "16889";

_Person.AddressList.Add(Address);

_Address = new Address();
_Address.Street = "1600 Pennsylvania Avenue";
_Address.City = "Washington";
_Address.State = "DC";
_Address.Zip = "20001";

_Person.AddressList.Add(Address);

_Person.Save();

Thanks in advance.

Jon

__________________________________________________

The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.

Reply to this message...
 
    
Tim Musschoot
This is a good solution. What I would change is the constructor of your
classes:

public Address(String Street, String City, String State, String Zip)
{
    _Street = Street;
    _City = City;
    _State = State;
    _Zip = Zip;
}

_Adress = new Address("100 Main Street","Erie","IN","16889");

It saves you a couple of lines :-). You might consider doing the same for
the Person constructor

Best Regards,
Tim Musschoot

-----Oorspronkelijk bericht-----
Van: Jon Ceanfaglione [mailto:Click here to reveal e-mail address]
Verzonden: vrijdag 2 augustus 2002 13:51
Aan: aspngcs
Onderwerp: [aspngcs] Collection of Objects

I have two objects, let's say person and address. I want to allow person
objects to have multiple addresses. What is the best way to accomplish
this? I would think to create a collection of address objects that is
exposed as a property of the person object. I'm thinking something like the
following:

Person _Person = null;
Address _Address = null;

_Person = new Person();
_Person.Name = "John Doe";
_Person.BirthDate = "11/10/1969";

_Address = new Address();
_Address.Street = "100 Main Street";
_Address.City = "Erie";
_Address.State = "IN";
_Address.Zip = "16889";

_Person.AddressList.Add(Address);

_Address = new Address();
_Address.Street = "1600 Pennsylvania Avenue";
_Address.City = "Washington";
_Address.State = "DC";
_Address.Zip = "20001";

_Person.AddressList.Add(Address);

_Person.Save();

Thanks in advance.

Jon

__________________________________________________

The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Michael Iantosca
I agree with this approach too. What I normally do is create a few
overloaded constructors.

1 - one that accepts all of the values needed to create a new instance
of the object and set all of its values. I use this one to create a
brand new instance

    _Address = new Address("100 Main Street","Erie","IN","16889");

2 - another that accepts an id of some sort that corresponds to the
object's id in the database. I use this one to retreive an existing
object from the database.

    _Address = new Address(125);

3 - sometimes one that takes not property values but just creates an
empty instance (no property values set) - like your original version

    _Address = new Address();

My 2 cents
Michael

-----Original Message-----
From: Tim Musschoot [mailto:Click here to reveal e-mail address]
Sent: Friday, August 02, 2002 8:08 AM
To: aspngcs
Subject: [aspngcs] RE: Collection of Objects

This is a good solution. What I would change is the constructor of your
classes:

public Address(String Street, String City, String State, String Zip) {
    _Street = Street;
    _City = City;
    _State = State;
    _Zip = Zip;
}

_Adress = new Address("100 Main Street","Erie","IN","16889");

It saves you a couple of lines :-). You might consider doing the same
for the Person constructor

Best Regards,
Tim Musschoot

-----Oorspronkelijk bericht-----
Van: Jon Ceanfaglione [mailto:Click here to reveal e-mail address]
Verzonden: vrijdag 2 augustus 2002 13:51
Aan: aspngcs
Onderwerp: [aspngcs] Collection of Objects

I have two objects, let's say person and address. I want to allow
person objects to have multiple addresses. What is the best way to
accomplish this? I would think to create a collection of address
objects that is exposed as a property of the person object. I'm
thinking something like the
following:

Person _Person = null;
Address _Address = null;

_Person = new Person();
_Person.Name = "John Doe";
_Person.BirthDate = "11/10/1969";

_Address = new Address();
_Address.Street = "100 Main Street";
_Address.City = "Erie";
_Address.State = "IN";
_Address.Zip = "16889";

_Person.AddressList.Add(Address);

_Address = new Address();
_Address.Street = "1600 Pennsylvania Avenue";
_Address.City = "Washington";
_Address.State = "DC";
_Address.Zip = "20001";

_Person.AddressList.Add(Address);

_Person.Save();

Thanks in advance.

Jon

__________________________________________________

The information contained in this communication is intended only for the
use of the recipient named above, and may be legally privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this communication is not the intended recipient, you are
hereby notified that any dissemination, distribution, or copying of this
communication, or any of its contents, is strictly prohibited. If you
have received this communication in error, please re-send this
communication to the sender and delete the original communication and
any copy of it from your computer system. Thank you.

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Jon Ceanfaglione
Now that we agree on that, let me get further into my question.

I have a person object, and an address object. These objects have
PersistanceManager objects that manage db work.

The address object accepts a ID for the user, and other address fields like
street, etc...

I also have an AddressList object that represents a collection of address
objects. The AddressList object only has 2 public properties (count and
add), and an internal member called ListOfAddresses (internal because I want
a method in the person object to be the only access point to the address
collection). This object is exposed via a property in the person object.

What I'm struggling with is where is the best place to put the code to check
the address collection, iterate through, and call the save command on the
address objects. In the PersistanceManager for Person ?

Obviously, I can do this directly if I want:

Address _Address = new Address();
_Address.User = 123; //User ID
_Address.Street = "100 Main Street";
_Address.City = "Erie";
_Address.State = "IN";
_Address.Zip = "16889";
_Address.Save();

However, the idea should be that the client simply adds address objects to
the collection - calling Person.Save() should update any addresses found in
the collection. I guess I'm answering my own question... are there any
objections so far?

Thanks.

Jon

-----Original Message-----
From: Michael Iantosca [mailto:Click here to reveal e-mail address]
Sent: Friday, August 02, 2002 8:42 AM
To: aspngcs
Subject: [aspngcs] RE: Collection of Objects

I agree with this approach too. What I normally do is create a few
overloaded constructors.

1 - one that accepts all of the values needed to create a new instance
of the object and set all of its values. I use this one to create a
brand new instance

    _Address = new Address("100 Main Street","Erie","IN","16889");

2 - another that accepts an id of some sort that corresponds to the
object's id in the database. I use this one to retreive an existing
object from the database.

    _Address = new Address(125);

3 - sometimes one that takes not property values but just creates an
empty instance (no property values set) - like your original version

    _Address = new Address();

My 2 cents
Michael

-----Original Message-----
From: Tim Musschoot [mailto:Click here to reveal e-mail address]
Sent: Friday, August 02, 2002 8:08 AM
To: aspngcs
Subject: [aspngcs] RE: Collection of Objects

This is a good solution. What I would change is the constructor of your
classes:

public Address(String Street, String City, String State, String Zip) {
    _Street = Street;
    _City = City;
    _State = State;
    _Zip = Zip;
}

_Adress = new Address("100 Main Street","Erie","IN","16889");

It saves you a couple of lines :-). You might consider doing the same
for the Person constructor

Best Regards,
Tim Musschoot

-----Oorspronkelijk bericht-----
Van: Jon Ceanfaglione [mailto:Click here to reveal e-mail address]
Verzonden: vrijdag 2 augustus 2002 13:51
Aan: aspngcs
Onderwerp: [aspngcs] Collection of Objects

I have two objects, let's say person and address. I want to allow
person objects to have multiple addresses. What is the best way to
accomplish this? I would think to create a collection of address
objects that is exposed as a property of the person object. I'm
thinking something like the
following:

Person _Person = null;
Address _Address = null;

_Person = new Person();
_Person.Name = "John Doe";
_Person.BirthDate = "11/10/1969";

_Address = new Address();
_Address.Street = "100 Main Street";
_Address.City = "Erie";
_Address.State = "IN";
_Address.Zip = "16889";

_Person.AddressList.Add(Address);

_Address = new Address();
_Address.Street = "1600 Pennsylvania Avenue";
_Address.City = "Washington";
_Address.State = "DC";
_Address.Zip = "20001";

_Person.AddressList.Add(Address);

_Person.Save();

Thanks in advance.

Jon

__________________________________________________

The information contained in this communication is intended only for the
use of the recipient named above, and may be legally privileged,
confidential and exempt from disclosure under applicable law. If the
reader of this communication is not the intended recipient, you are
hereby notified that any dissemination, distribution, or copying of this
communication, or any of its contents, is strictly prohibited. If you
have received this communication in error, please re-send this
communication to the sender and delete the original communication and
any copy of it from your computer system. Thank you.

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

__________________________________________________

The information contained in this communication is intended only for the use
of the recipient named above, and may be legally privileged, confidential
and exempt from disclosure under applicable law. If the reader of this
communication is not the intended recipient, you are hereby notified that
any dissemination, distribution, or copying of this communication, or any of
its contents, is strictly prohibited. If you have received this
communication in error, please re-send this communication to the sender and
delete the original communication and any copy of it from your computer
system. Thank you.

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification