I'm a bit confused when it comes to Object oriented programming for say a 3 tier application. Here is just a small example of what I am trying to do (I will shorten the database design to make it simple). Assume I am making a ticket help desk system. A ticket has a description, a responsible person, a due date, and of course an ID (unique).
Assume the ID is just an IDENTITY column that is of type integer and gets its value automatically (SQL Server). That is it gets its value only after an insert has been done.
Now just some sample pseudo code (it may not be right, so dont let the syntax bug you out, just trying to get an answer about how to store the ID).
I could easily create a Ticket class
public class Ticket
{
private string m_description;
private date m_duedate;
private string m_responsible;
private int m_id; //should this be read only ??? or...how
//then I can have a bunch of Properties to get / set these private variables
public Property Responsible{
get
{ return m_responsible; }
set
{ m_responsible = value; }
}
//and so on..again dont worry about syntax. Now should I have a get / set for the ID?
}
Ok so I have this class called ticket..but what happens when I create a ticket object and need to insert it from my BLL (Business Logic Layer)
Bll b = new Bll();
Ticket t = new Ticket();
t.Responsible = someString;
t.DueDate = someDate;
t.Description = someLongString;
//use the BLL to create a ticket object and pass it to the DAL ?
//then assign the ID from the database to t.ID ???
t.ID = bll.InsertTicket(t);
//that is pass it to the BLL, which does its thing, and passes it to the DAL does an INSERT statement and then returns the ID number given to it by the database.
So my question is how or when do I need to assign t.ID or do I even need to given after its inserted I am done. I always get confused with OOP because I tend to think it complicates things more then just passing a whole slew of parameters.
Ok so after someone can help me understand whether I need a get/set on the ID and whether I should pass that value back to my interface. My second question is what about updates? Assume an end user finds a ticket, so on my interface I retreive some ticket data and someone wants to update say the description and due date. When I "Submit" these changes, should I just create a ticket object, set all the get / set property values and thats it? Or should I just pass in the ID number and all the paramters to my BLL and let it handle it all?
Hope this all makes sense!
Thanks so much guys!