views:

36

answers:

1

In my projects I am using 4 layers (userinterface, custom types, business logic and data access layer).

I heared a lot about benefits of properties but in practicle I just used business objects for transfering data between layers and not getting any benefit of properties.

I read that business rules, validations and checks can be implemented using properties but all these are done on front end using validation controls and regular expressions which even give good user experience. (I further do server side validations using same validaters and regular expressions before sending data to DB.)

Please guide me what are basic strength and use of properties ? Why they are important and how they bring benefits.

+1  A: 

Right now, I can think of two possible usages of properties in Business objects.

1) Computed properties. A readonly property returning some value based on other fields/properties of the object.

eg:

public double AmountToPay { get { return _price*qty; }}

This logic should stay inside business object because tommorrow you may want to add some surcharge in the amount, and keeping it inside the object would reflect the new amount to all the users.

2) Validation properties A property stating that the created instance of a business object (or some part of it) is valid or not.

eg:

public bool IsAValidPrice { get { return _price > 0 ; } }

Again, tommorrow the business may allow some items to be sold for free, and then the logic would include the items with price==0 as a valid price.

Amby
Thanks Amby, What you say is correct but I have felt in practicle it is not practice. If we are working on web, we must do client side validations and using validation controls and regular expression validations using properties looks useless. Thats why I was trying to see real use of properties. Please advice.
haansi
I agree, in case of plain html+javascript based application it is not that straight. You may consider using some Ajax/JQuery to allow more interaction between client-server. Will sure get back to you if i find a better answer. Cheers!
Amby