?
Solved

Data Objects

Posted on 2011-02-28
3
Medium Priority
?
247 Views
Last Modified: 2012-05-11
I am currently using data obejcts with something like the code below.    I was going to try to seperate the "Contact" and the data access i.e the load contact etc .  Is this a recomended apporach is there a particular pattern for this.

Sorry for the vague questions just need some direction on this.


Class Contact

Property Firstname as String
Property Surname as String

Public Function LoadContact(ContactID as integer) as Contact
End Sub

Public Function LoadContacts(OrgID as integer) as BindingList(of Contact)
End Sub

Public Sub UpdateContact(Contact as Contact)
End Sub


End Class
End Sub





0
Comment
Question by:Kevin Robinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1000 total points
ID: 34996604
What you have defined at the moment is know as teh "active record" pattern. What that means is that you are embedding the details of how the object is stored/retrieved into the object itself. The pattern is perfectly valid, but is also a lot more restrictive.

Extracting the details of how to load/save an object into a seperate object (or even a seperate layer) will give you a lot more flexibility and make your object more light-weight in the long term.
0
 
LVL 11

Assisted Solution

by:Sudhakar Pulivarthi
Sudhakar Pulivarthi earned 1000 total points
ID: 34997672
HI,
Yes what you  have designed is good which isolates code for Contact into a single class but logically when used in app the flexibility is more when we clearly segregate the data with logic.

I have not used VB instead i try to provide code in C# and explain the concept.

Create a Contact data object class which holds the data completely defining about contact.
Class Contact
{
private string _firstName;
private string _surname;

Public string FirstName
{
get{return _firstName;}
set{_firstName = value;}
}
Public string SurName
{
get{return _surname;}
set{_surname= value;}
}
}

Have a class to interface and use the Contact data objects extensively in the code with the properties which are exposed by the Contact object.
Additionally you can save/update to DB/Load the contact data objects using this class which gives a clear line of DATA/LOGIC segregation in the code.

Hope this clarifies...
0
 
LVL 3

Author Closing Comment

by:Kevin Robinson
ID: 35080917
Very useful comments Thank you
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question