Blue Ink
Blue InkHomeBlue Ink SolutionsArticlesBlue Ink Net CommunityBlue Ink Demo ApplicationAbout Automated Architecture
My Profile
login/register
0

When is the right time to load data for a class?

View General Forum | Post Response | New Topic

Author Message
dakinney0807
Dec 4 2006
5:07 PM
I'm creating a class that is going to hold some info of the logged in user for a tool that I'm creating.

Usually when I create a class I create an empty constructor, a full constructor and a Load method that will fill all of the variables with values from the db. So basically to do it in the code I have to do this:

Class var = new Class();
var.Load();

Do you think, becuase I know I'm going to fill it with the same info every time, it'd be better for me to put the Load logic in the full contstructor, or keep it like it is?

Lee Richardson
(Admin)

Dec 4 2006
5:17 PM
dakinney0807,

I guess it’s all personal preference and how it will be used. If the DB retrieval logic is in the constructor then you have the advantage of knowing that if you have an instance it’s already populated and you don’t need to check if it is. If you do it in a load method you might need to check class.IsLoaded. So I suppose I might lean toward putting it in the constructor, but again it depends on how it’s used.

Personally, though, I would go with a different architecture all together and separate out responsibilities further by using a dataset or very light class to hold the database information (aka "business entities") and have a non-state holding class that performs the loading (aka "Data Access Logic Component" or DALC) and have a third class that performs the business logic (aka "Business Entities").

This is how Microsoft recommends per Application Architecture for .NET: Designing Applications and Services:

http://www.microsoft.com/downloads/details.aspx?FamilyId=A08E4A09-7AE3-4942-B466-CC778A3BAB34&displaylang=en

It’s a little more code, but of course that’s what code generators like Blue Ink are for. :)

abinkuser
Aug 27 2007
7:55 AM
Other article called "Exception Management Architecture Guide" maye be more useful, it can download form MS, An exception management system should be well encapsulated and should abstract the details of logging and reporting from the application's business logic.

---------------
[url=http://www.softsea.com]latest softwares[/url]

View General Forum | Post Response | New Topic






ARTICLES

What is Rapid Application Development?


QUESTIONS?

Call us toll free:
(877) 756-3595

Or Visit Forums

    

Copyright © 2017 Automated Architecture, Inc. All rights reserved.