Solved

Data Objects

Posted on 2011-02-28
3
208 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
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now