Solved

Data Objects

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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