Is this correct OO design?



I'm not sure if this is bad design or not. It seems flawed, but I'm not
sure. Is it wrong to create an instance of a class within the class
itself? Any feedback appreciated.

public class Article
{
int articleID;
string title;

//Constructor: Load Data from DataAccess Class
public Article(int articleID)
{
this.articleID = articleID;

//Set properties of Article Object with values from Database
DataAccess.GetArticleData(this, articleID);
}

public void Update()
{
/*
IS IT BAD OO DESIGN TO CREATE AN INSTANCE OF A CLASS
(OriginalArticle) WITHIN THE CLASS ITSELF(Article)?
*/

Article OriginalArticle = new Article(this.articleID);

//check to see if the new and origianal values match
if(this.title != OriginalArticle.Title)
{
Response.Write("<br>Title doesn't match current Title in
Database...Perform Important Operation Here.");
}
else
{
Response.Write("<br>Title hasn't changed.");
}
}

public string Title
{
get{return title;}
set{title = value;}
}
}

public class DataAccess
{
public static void GetArticleData(Article article, int ArticleID)
{
//load database data, populate Article object from parameter
article.Title = "Original Title from Database";
//article.Field1 = ...
//article.Field2 = ...
//etc...
}
}

public class _Default : Page
{
private void Page_Load(object sender, EventArgs e)
{
Article MyArticle = new Article(2112);
Response.Write("<br>MyArticle.Title: "+MyArticle.Title);
MyArticle.Title = "New Title from MyArticle object instance";
MyArticle.Update();
}
}

results:
MyArticle.Title: Original Title from Database
Title doesn't match current Title in Database...Perform Important
Operation Here.

.



Relevant Pages

  • Re: Is this correct OO design?
    ... This is NOT bad design. ... look at the timestamp data type in SQL Server, and Optimistic Concurrency ... > (OriginalArticle) WITHIN THE CLASS ITSELF? ... > public static void GetArticleData ...
    (microsoft.public.dotnet.general)
  • C# programmer looking for a job
    ... Software Development including Desktop, Client/Server and Database ... Practical skills in object oriented design and design patterns ... XML, Oracle, CVS, VSS, Delphi, bug tracking. ... Developed in Delphi5; ...
    (misc.immigration.usa)
  • Re: O/R Mapper
    ... | - create E/R model from niam model ... classes that contain, not only data, but also functionality as OO design is ... a database where they do not exist in the object model is corrupting the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Date range on reports
    ... > box to your report with a control source like: ... >> In the Database window (Database window: The window that appears when you ... >> In the New Form dialog box, click Design View, and click OK. ... >> Begin by clicking Macro Names to display the Macro Name column. ...
    (microsoft.public.access.reports)
  • Re: limit of lines?
    ... And this is the fundamental mistake in your design. ... a objects from a database, this usually leads to very poor design. ... Framework in which all properties are backed, not by a simple field, but by ... we have major size projects that use the Delphi template ...
    (borland.public.delphi.non-technical)