30 ตุลาคม 2549 5:12Can anyone plz tell when we should use delegate in dot net application.
Another question of my is through property set or get method what quality of Object oriented we get i mean Data Abstration or Encapsulation.
Thanx in advance
30 ตุลาคม 2549 5:40
Delegate is used to achive the Event Driven Pattern
- designed for a Method
- Call Back on Asyncronus Call to the Methods
- To link multiple delegate for single event.
- Multi Process/Thread communication/messaging on Single Domain/System
30 ตุลาคม 2549 5:42yeah dats i know.Actually througjh delegates we can call any function runtime.So i want that scenario where we should use delegates then inspite of if else condtion to call dat fucntion
30 ตุลาคม 2549 7:28A common scenario is when you define a custom event in your component - you don't know which is the method/function to be called when event is raised. So, you let the component user to indicate it.
Make it sense?
More details here:
30 ตุลาคม 2549 8:30I got the first answerr now my second question was what quality of OOPs we got through property in dot net.
30 ตุลาคม 2549 14:50I don't know what you mean by quality of OOPs, but it achieves the same things as get/set methods in a C++ or Java program. Though, in my opinion, the syntax for properties is more expressive. Additionally, it clearly delineates what an object's properties are, whereas this isn't so clear in a Java class. This helps when making tools that use reflection to manipulate an object at design time.
30 ตุลาคม 2549 16:58
Debabrata.debroy wrote: I got the first answerr now my second question was what quality of OOPs we got through property in dot net.
They needed a concept between method and field, and they invented it: properties. Which were the possibilities we had before to expose a class field?
- Create a method which returns the private field, but where is the behavior of this method?
- Exposing the class field (i.e. make it public) would break on of OOP concept: encapsulation.