views:

29

answers:

1

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?

+1  A: 

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.

NikhilK
Yeah we need the setter because the serialization abilities lacks in SL4.This could easily be solved with .NET there the serialization attribute is available and can get; set private fieldsWell to set the Id, a field for the new entity which should not be changed, then the use of the constructor is a excellent solution.For recaculation of prices and so on, we surely want to use the same logic at the server side later and this will be business logic in the ViewModel that I think belongs in the domainmodel.But I may have been missed something as you write that I do not need to duplicate it.
NPehrsson