R
rick walsh
I am trying to write an application that displays news articles on a web
page.
I have recently moved to C# and currently I am trying to learn how to use
good Object Oriented design.
I assume that I should create a class called mynews. This will hold member
information such as headline, date, bodytext etc.
This can then be called by a page to display a single news item. ie
mynews objmynews = new mynews(1)
label1.Text = objmynews.headline;
label2.Text = objmynews.date;
label3.Text = objmynews.bodytext;
The mynews class would talk to the database only once to do this.
However, if I want to produce a listing of news items I would have to
instantiate this class many times resulting in many calls to the database.
For example:
mynews objmynews = new mynews(1)
label1.Text = objmynews.headline;
label2.Text = objmynews.date;
mynews objmynews = new mynews(2)
label3.Text = objmynews.headline;
label4.Text = objmynews.date;
This is clearly not effeicient. How should I code this?
Should I write an additional class? Is this good oo design?
Help I'm stuck!!!
Many thanks.
Rick
page.
I have recently moved to C# and currently I am trying to learn how to use
good Object Oriented design.
I assume that I should create a class called mynews. This will hold member
information such as headline, date, bodytext etc.
This can then be called by a page to display a single news item. ie
mynews objmynews = new mynews(1)
label1.Text = objmynews.headline;
label2.Text = objmynews.date;
label3.Text = objmynews.bodytext;
The mynews class would talk to the database only once to do this.
However, if I want to produce a listing of news items I would have to
instantiate this class many times resulting in many calls to the database.
For example:
mynews objmynews = new mynews(1)
label1.Text = objmynews.headline;
label2.Text = objmynews.date;
mynews objmynews = new mynews(2)
label3.Text = objmynews.headline;
label4.Text = objmynews.date;
This is clearly not effeicient. How should I code this?
Should I write an additional class? Is this good oo design?
Help I'm stuck!!!
Many thanks.
Rick