0

Partial methods - what good are they?

by klh 31. januar 2008 15:52

So i attented the Aarhus .net User Group the other day.

Henrik Lykke Nielse of Captator gave an introducion to most of the updates to .net framework 3.5 and C# 3.0.

Most of it was known to me - however one thing that I had not heard about before was partial methods.

Partial methods are methods where you define the declaration of the method in one part of a partial class( a bit like C++ header files) and maybe choose to implement it in another part of the partial class. I say 'maybe' since you can choose to not implement the partial method, and if so all calls to the method is simply erased.

"So what good is this?", I thought to myself and asked Henrik. To this he responded that for instance you can implement functionality without thinking about instantiating classes.

Let me explain: One could do similiar stuff by making virtual methods, but the framework would then have to depend on factories and such to instantiate the correct objects for you.

However if you declare a partial method in the framework, and let be up to the user of the framework to implement the partial method or not - you get rid of all the factory fuzz.

Nice trick I think!

Tags:

C# | generelt

Kommentarer

Tilføj kommentar


(Viser dit Gravatar icon)  

  Country flag

biuquote
  • Kommentar
  • Eksempel
Loading



Powered by BlogEngine.NET 1.4.5.0
Original Design by Laptop Geek, Adapted by onesoft