Solved

Data Objects

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now