Silverlight is great, and with RIA services solves alot of stuff BUT.
Why are we forced to have get; set on every model?
I have been learned that if we have an Customer and the Customer Id should never change, then the Id property should be readonly, if the customer has an password that need to go through some logic before it shall be set the property should be readonly so noone can use my object in a wrong way.
And one of the biggest things we should almost never allow get; set on collections on for example invoice.Rows because it could create bugs hard to find. Maybe I want to block the invoice.Rows.Add (that by the way breaks Law of Demeter principle) method because I want to do some checking within an method invoice.AddRow(row); before adding the row.
Sometimes we want to solve this at the serverside for examplesending the row for the invoice over the service when its being added, but sometimes we want to build the whole invoice at the client and then send it over. I do not wanna need to ask the service hey I’ve just added this row can I get the recalculated totalprice with vat and without vat and so on.
Am I’m the only one who feels lost, or are my aiming and goals wrong, should’t we use silverlight with object oriented thoughts?
The need for the getter stems from serialization – you want to be able to set during deserialization.
You also want to be able to set the ID for a new entity, if your IDs aren’t auto-generated.
As for Order/OrderDetail, in general we expect Order/OrderDetail represents a compositional scenario – you either insert an order with details, or update an order to add/delete/update order details. So if you want to do validation that spans the whole graph, you can attach a validation rule to either Order, or to methods like InsertOrder, UpdateOrder.
As for recalculating total price etc. you can certainly do that on the client – for example, listen to collection change notifications on the Details collection, and recompute the Total property of Order. The code to enumerate Details and do the aggregation can in fact be shared across client and server so you aren’t duplicating computation logic.
Hope that helps.