Brad Pears said:
That was very well written. I had never thought of having a property
'State' that is set for the object but I think it makes sense...
Basically what I have happeneing now is that the "Save" method on the
business class "contract" object calls an "update" method on the contract
"data class" object. ( I split the object so that I have a business object
"contract" and a data object "contract_data"). This update method in turn
runs a stored procedure to do the job. The stored procedure itself
determines whether or not to "update" the data or "insert" the data. There
is a completely separate method to "delete" a contract which in turn runs
a stored procedure to specifically do just that...
I like to separate all three functions of add, update or delete, whether
that be with a stored procedure or with dynamic SQL statements in code.
So implementing a state property really doesn't buy me anything in this
instance BUT I do like the idea of having a state on every object and I
think it makes sense. Is this a common thing to have?? I have not seen a
lot of this in reading OO material or viewing OO design techniques/coding
techniques...
The state property, which can also be implemented at the business level as
well allows one to know the state of the object when dealing with the object
at the UI, Business or Data Access level.
I always at any level of the logical tiers of UI, Business and DALC I want
to know the object's state. Object what is your state so that I can take the
correct processing path.
Take for instance the case where you have a Business Object Collection a
collection that's holding multiple business objects, and during the
BOC.Save, it starts walking the collection invoking each object's
object.save, then I may need to know the state of the object. Maybe, I need
to populate an object with a parent key from a parent object or other things
like that, before I save the object.
What's the state of the Business Object Collection is the BOC DIRTY, because
a object within the BOC has been marked DIRTY so it's DIRTY too? Why should
I invoke the BOC.Save and start walking the collection when no object is
DIRTY within the BOC, because the user pushed the Save button?
There is another state of an object called IsValid. The object is asked to
validate itself. If the object is not valid, the why should I invoke the
Object.save? If all objects are not valid within the BOC if its IsValid is
false, then why should I invoke the BCO.Save.
Where I leaned all of this in using VB 6 for those solutions back in the
day, VB.NET and C#.NET, which I have been using these OOps concepts, since
year 2000, from Web, Windows desktop, Console and NT Service applications
for .NET is CSLA.
http://www.lhotka.net/Article.aspx?id=1351540e-b941-446a-bacb-e0059cc82ee7
If you like, you can get the book, read the book, understand what's in the
book, download the framework put it together, download the project put it
together to use the framework and then you'll understand OO programming
techniques.
Keep in mind now, it's not about trying to implement a framework, which most
companies do use some kind of framework, in house written as an example.
It's about understanding the concepts, who are the players and how are the
players being used.
And then saying to yourself, I can use these concepts, I can make my own
objects, I don't need the CSLA framework, and I can run with this myself.