Blue Ink
Blue InkHomeBlue Ink SolutionsArticlesBlue Ink Net CommunityBlue Ink Demo ApplicationAbout Automated Architecture
My Profile

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

View General Forum | Post Response | New Topic

Author Message
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();

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

Dec 4 2006
5:17 PM

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:

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

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=]latest softwares[/url]

View General Forum | Post Response | New Topic


What is Rapid Application Development?


Call us toll free:
(877) 756-3595

Or Visit Forums


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