Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class question 1

Status
Not open for further replies.

blar9

Programmer
Mar 12, 2007
39
US
I have an app I am wanting to build it in as OO as possible. I have a user who can have multiple addresses. What I have done is create an address class and an addresses class. Addresses is a collection of address and it has properties like item, count, delete, ect... class address has the actuall address information so in the code I can run:

dim add as new address
dim addresses as new addresses

add.address1 = "123 address"
add.City = "city"

Addresses.Add(add)

3 questions:

1.) is this a good way to do this

2.) I have clients and employees how do I attach addresses to them. Same way instanciate client and do client.addresses.add(add) if so how do I make addresses part of client class?

3.) When a someone looks up a client is it faster to load multiple addresses and client information all at once or wait until the addresses are requested and hit the db a second time?

Thanks for any help!
 
3 questions:

1.) is this a good way to do this
yes, you could also use generics if you need a simple list.

2.) I have clients and employees how do I attach addresses to them. Same way instanciate client and do client.addresses.add(add) if so how do I make addresses part of client class?
Code:
public class Client
{
  private IList<Address> addresses;

  public Client()
  {
      addresses = new List<Address>();
  }

  public void Add(Address address)
  {
     addresses.Add(address)
  }

  public void Remove(Address address)
  {
     addresses.Remove(address)
  }

  public void ClearAddresses()
  {
     addresses.Clear();
  }

  public void GetNumberOfAddresses()
  {
     return addresses.count;
  }

}

public class Address
{
}

3.) When a someone looks up a client is it faster to load multiple addresses and client information all at once or wait until the addresses are requested and hit the db a second time?
1st design the domain (domain driven design; Evans), then worry about preformance. preformance isn't an issue until someone says it's an issue. They don't need to know if everything is loaded at once, or one at a time.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top