Solved

Data Objects

Posted on 2011-02-28
3
216 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

11 Experts available now in Live!

Get 1:1 Help Now