haansi
haansi

Reputation: 5730

benefit of properties in business objects?

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.

Upvotes: 0

Views: 180

Answers (1)

Manish Basantani
Manish Basantani

Reputation: 17509

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.

Upvotes: 1

Related Questions