Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Polymorphism in C# [Object-oriented Programming]

Five stars Perplexity good job. Make sure to submit it on the competition thread.
(Feb 1, 2013 04:40 PM)tweety Wrote:  Now Skid's can shut up about Polymorphic hax and learn what it actually means in OOP. Rated 5.

People are still using the proper definition, they're just referring to Polymorphic Encryptions.
(Feb 1, 2013 04:45 PM)pr3fix Wrote:  Pretty basic, yet I believe that it will be useful to beginners. Good job :)

Translation: I'm really good at C# and I want you all to know that I already know how to do this.

Thanks for the tutorial OP.
(Feb 1, 2013 04:54 PM)Koolg223 Wrote:  Translation: I'm really good at C# and I want you all to know that I already know how to do this.

Thanks for the tutorial OP.

This is one of the most basic things someone should learn. If you don't know how to do this and you say you can code in C#, then there is something wrong with you.
(Feb 1, 2013 05:02 PM)Occulta Wrote:  This is one of the most basic things someone should learn. If you don't know how to do this and you say you can code in C#, then there is something wrong with you.

And you've missed the point entirely...

Also, you're wrong, there are many far more basic things. If you polled this forum, I'm guessing at least 50% of people here don't know how to use it.
Hopped over from the vb section and saw this...

Very impressive write up and explanation, I do love how you got the message across in a simple and understanding way.

Thanks for all the work and thought you put into this man :P
very good tutorial, I understood everything.Thank you to the animals !!! very good idea ...
Thanks..
(Feb 1, 2013 04:54 PM)Koolg223 Wrote:  Translation: I'm really good at C# and I want you all to know that I already know how to do this.

Thanks for the tutorial OP.

No, he's just speaking truthfully. A form of anonymous type/methods; this is not new (every obfuscatord does this), isn't poly or even close, and provides no purpose as it's not explaining the reason why the framework has anon methods/types in the first place, nor what type casting is. There is a much greater purpose for this in OOP, than just theoretical guessing of "polymorphism". In the end, you've given them a great tool for the wrong job, and didn't explain what the tool is for, only what it does.

.NET being a translated language run in a virtual machine, with the highest degree of late-binding of any langauge/framework, has much better avenues to explore for poly than most other languages. Think of this way;

1. Anything, and everything can be called via a string in .net with reflection besides datatypes.. And I mean everything besides the 2-3 methods needed to reflect (and there are workarounds even for that)

2. A virtual machine (CLR) just translates code of the executable. But what happens if you can change that translation from within the virtualmachine? You can then change classes, methods, datatypes... Lets say I want to call "Console.Read", we can change that to "Microsoft.Sucks". Anything can have is translation changed, thereby leaving room for almost every bit in the executable to be dynamic... If you know how to inject msil already, it's a fairly straight forward process of hijacking the methods you want to change by injecting code into their libraries (dll's inside .net folder or memory) and changing their names.

True examples of poly in languages like c, show use of their own custom virtualmachine, yet .net has the best vm already made and it's easily modifiable with little a little skill. Mono is an example of a modified CLR.
Implicit operator overloads could avoid type casting though.

Code
public static implicit operator Cat(Animal a)
{
    return (Cat)a;
}
(Mar 15, 2013 08:29 PM)TxTriton Wrote:  You're still typcasting there lol.

Code
return (Cat)a;

What you should have done is return a new Cat with the implementation of that Animal class for everything that they would have in common, then set the rest of the unique implementations of Cat to defaults.

I would avoid implicit conversion operator overloading anyways, a conversion method would be 100 times better. Ex: Cat.FromAnimal()

I know, what I meant was that you wouldn't need to manual type cast.
Good use of analogies, I wish I had this when I started programming, life would have been wayyyy easier haha.
Anywho, nice tutorial, I would reccommend this thread to anyone starting programming, 5 stars from me. (:


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Russian bearFeb 21, 2022 08:06 PM 3 240 Feb 21, 2022 08:06 PM
Last Post: MavenGradle
[C#] by NvikodvJan 18, 2019 06:43 PM 0 160 Jan 18, 2019 06:43 PM
Last Post: Nvikodv
[Java] by deadsh0tJan 10, 2019 07:30 AM 2 171 Jan 10, 2019 07:30 AM
Last Post: deadsh0t