where T:- means you want some constraints to be implemented when client passes T as a type parameter.Let's analyze this line where T : class, K, new(): T parameter has " where" constraint which depicts that T should be a class, it should be inherited from K and its instance can be created. It takes two parameters, i.e., " K" and " T". Here, I have created FactoryPattern class using generics. You might be wondering what's all this ? :-). NOTE: I have taken ReportGenerator and ReportAnalyser classes for example purposes only. So, we start with creating two simple classes, i.e., ReportGenerator and ReportAnalyser which share a common interface implementation IActivity. Then, we will go about changing the same factory pattern using generics and you will see the difference. First, I will show you the implementation of Factory pattern without using generics. Backgroundįor those who don't know Factory Design Pattern, please refer to this article of GOF available at below mentioned link: I will be showing Factory Design Pattern using generics in. You can create your own design pattern class library which could be then made re-usable in any project. Think if these design patterns are made using generics in. This article reveals some good use of design patterns using generics.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |