|
I've known about Generics for a while, but never really took the time to review. I've recently began taking a look at them and have been trying to determine when they should be used. It seems I can do the same things using inheritance. I was just wondering about everyone's opinion on this topic.
Do you prefer one technique over the other and why?
What scenario would a Generic be a better choice than an inherited class?
Thanks.
|
|
|
|
|
Generics and Inheritance are two completely different animals. Inheritance is of course used for OO where you can have a base class with some characteristics and actions that can be used in any derived classes. The classical example is and Animal base class and Cat or Dog derived classes.
Generics give you the ability to write one class or method that can execute actions in a generic way. For instance;
public class MathOperations
{
public T Add<T>(T x, T y)
{
return x + y;
}
}
In this case you can call Add with int, float, decimal, etc. and it will add the values together. Otherwise you would need to create an override for the Add method that takes, int, float, double, etc., much more coding.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Looks like a <T> got eaten by the hamsters
|
|
|
|
|
Guess Bob got hungry
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Can't compare one with other. Inheritance is used in Object Oriented Programming and Generic is used in Generic Programming. One can't replace the advantage of one with other.
Personally i perfer to use Generic for utility classes such as vector, array, map, list etc and inheritance for contract. What does it means, with the help of inheritance, i want to make sure that we uses the appropriate level of classes.
Take a look at the following example
class Building
{
}
class ResidentialBuilding : Building
{
}
class RentedResidentialBuilding : ResidentialBuilding
{
}
class ApartmentBuilding : RentedResidentialBuilding
{
}
class LuxaryApartmentBuilding : ApartmentBuilding
{
}
Now if i want to give some functionality of Apartment then i would do something like this
void ApartmentName(const ApartmentBuilding& apartment);
This way i will make contract, with the help of inheritance, that only apartment and its inherited class can be used with this function. We can't do exactly the same with Generic.
Similarly we can't do everything which generic offers with inheritance alone. The other answer already explained it.
|
|
|
|
|
|
Picture a bath. A conical bath. Film fine white sand running out of it. Now run the film backward.
|
|
|
|
|
I have a solution with 10+ projects. Most of the projects are 100% .net 2.0. However one of the projects references a .Net 3.0 DLL. The solution compiles fine in VS2008, but will not compile with VS2010, because of the mixed frameworks. We may be able to upgrade to .Net 3.5, but that will be later on. Has anyone else found a solution to this issue? Currently the solution is in VS2005.
GSC
|
|
|
|
|
gscheek wrote: will not compile
and what does that mean?
|
|
|
|
|
When trying to compile the solution, it contains 1000+ errors. VS2008 compiles fine with no errors.
GSC
|
|
|
|
|
really? that is horrible. I haven't been playing with VS2010 myself but that is not the behavior I expect, nor what I gathered from reading lots of posts in the Visual Studio forum and Lounge.
Do you have .NET 2.0 installed? (yes the Framework itself, not VS2008).
|
|
|
|
|
I've converted many projects from VS2008 to VS2010 and have not had any issues. Are they warnings or errors? What some of the errors you are experiencing?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
gscheek wrote: but will not compile with VS2010, because of the mixed frameworks
That really should not be the case.
When you opened the solution in 2010, did the conversion happen correctly?
|
|
|
|
|
When converting from 2005 - VS2008, it worked fine. But when converting the 2005 solution to VS2010, there was a warning for each project. The warning message was that the project is targeting 2.0 framework, but contained references to 3.0 .net dll's. If VS2008 didn't have an issue with this, why would VS2010.
Also, I have VS2005, VS2008, and VS2010 installed on the same machine.
Exact warning message from VS2010, it done this for several of the projects in the solution file.
Your project is targeting .NET Framework 2.0 or 3.0. If your project uses assemblies requiring a newer .NET Framework, your project will fail to build. You can change the .NET Framework version by clicking Properties on the project menu and then selecting a new version in the '.NET Framework' dropdown box. (In Visual Basic, this is located on the Compile tab by clicking the 'Advanced Compiler Options...' button.)
GSC
modified on Thursday, April 29, 2010 10:08 AM
|
|
|
|
|
gscheek wrote: Your project is targeting .NET Framework 2.0 or 3.0. If your project uses assemblies requiring a newer .NET Framework, your project will fail to build. You can change the .NET Framework version by clicking Properties on the project menu and then selecting a new version in the '.NET Framework' dropdown box. (In Visual Basic, this is located on the Compile tab by clicking the 'Advanced Compiler Options...' button.)
Did you try this?
|
|
|
|
|
yes,
I was trying avoid doing this though, since in VS 2008 it worked when I targeted the 2.0 framework. After I changed all the projects to 3.5 framework, many of the errors disappeared, but now other ones have come up. So I'm trying to get those fixed.
GSC
|
|
|
|
|
Hi all,
I'm excited to inform you that CodeFort with its release last week broke the barrier and became the first .NET obfuscator to support renaming of identifiers in XAML and BAML code. This is a huge step forward in .NET obfuscation technology, because it removes the need to manually exclude all the Presentation Layer properties and types from obfuscation, as you need to with most obfuscation tools today. Of course it will mean a great improvement in security in terms of protecting your intellectual property rights from attackers.
CodeFort also comes with a range of powerful protection features such as Reference Scrambling and Anti-Tampering, making it a state-of-the-art protection tool. Reference Scrambling decouples the link between calls to external methods, and the reference to those methods, making it impossible for an attacker to browse through IL or disassembled code, because the method calls are pointing to unusable locations.
Check out the free version if you're interested - we are very much looking forward to your feedback!
CodeFort Free Edition
Best regards,
Christian
email: support (.) creatix.dk
modified on Wednesday, April 28, 2010 7:36 AM
|
|
|
|
|
Post it as News or as General (like information - Message Type).
Please don't post News or Information like Question.
Jinal Desai
|
|
|
|
|
Hi Jinal,
Thanks for your hint. I have corrected it now.
Best Regards,
Christian
|
|
|
|
|
I have done VB.net application by the functionalities of export the word documet. Its working fine in the developemnt machine. During the developemnt , i have added the MICROSOFT.OFFIVE.WORD.INTEROP is added.
I need to install in the clinet machine. How to make a setup with this com refrence file.
I need some hurry. Plz help me.
Thanks
|
|
|
|
|
Member 4619061 wrote: I need some hurry.
Another way to say urgent
Don't ask for urgent help, it is rude. We are all here voluntarily and although it may be urgent to you it not to anyone else.
Member 4619061 wrote: How to make a setup with this com refrence file.
It's not a COM reference, it's an assembly. That should give you an idea.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for yr quick reply.
I dont have much exp in setup creation. I lloked out google and got some idea. but i dont findout how to add assemblies and DB in the setup?
Plz help me
|
|
|
|
|
|
Create setup project.
Add .exe file of your project, it will automatically add all the dependency
dlls and references.
If it will not include com reference (MICROSOFT.OFFIVE.WORD.INTEROP)
then you can add it manually by adding file to your setup project.
That's it.
Jinal Desai
|
|
|
|
|