I'm a little confused when it comes to object-oriented programming, such as a three-tier application. Here is just a small example of what I'm trying to do (I will shorten the database design to make it simple). Suppose I make a help desk system. The ticket contains a description, a responsible person, a period and, of course, an identifier (unique).
Suppose an identifier is only an IDENTITY column that is of type integer and automatically gets its value (SQL Server). That is, it gets its value only after the insert is completed.
Now just some kind of pseudo-code example (this may be wrong, so don't let the syntax fail, just trying to get an answer on how to save the identifier).
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;
So, I have this class called ticket ... but what happens when I create a ticket object and it needs to be inserted 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);
//, which passes it to the BLL, which performs its task, and passes it to the DAL, executes the INSERT statement, and then returns the identification number provided 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 give after inserting it, I am done. I am always confused with OOP, because I tend to think that this complicates the situation, and then simply passes a lot of parameters.
So, after someone can help me figure out if I need to get / set the identifier and whether I should pass this value back to my interface. My second question is what about updates? Suppose that the end user finds a ticket, so on my interface I return some data about the tickets, and someone wants to update, tell me the description and the date. When I “Submit” these changes, should I just create a ticket object, set all the values of the get / set property and this? Or should I just pass in the ID number and all the parameters to my BLL and let it handle it all?
Hope this all makes sense!
Thanks a lot guys!