Question regarding used of delegates
-
2006年10月30日 上午 05: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
所有回覆
-
2006年10月30日 上午 05: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
-
2006年10月30日 上午 05: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
-
2006年10月30日 上午 07: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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconEventsDelegates.asp
-
2006年10月30日 上午 08:30I got the first answerr now my second question was what quality of OOPs we got through property in dot net.
-
2006年10月30日 下午 02: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.
-
2006年10月30日 下午 04: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.
More details here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconpropertyusageguidelines.asp

