tagged [polymorphism]
Will GetType() return the most derived type when called from the base class?
Will GetType() return the most derived type when called from the base class? Will GetType() return the most derived type when called from the base class? Example: Or
- Modified
- 8 Apr at 16:18
Polymorphism in WCF
Polymorphism in WCF I'm looking at building a WCF service that can store/retrieve a range of different types. Is the following example workable and also considered acceptable design: ``` [ServiceContr...
- Modified
- 25 Mar at 13:22
Why do we need virtual functions in C++?
Why do we need virtual functions in C++? I'm learning C++ and I'm just getting into virtual functions. From what I've read (in the book and online), virtual functions are functions in the base class t...
- Modified
- 3 Sep at 16:18
How to specify polymorphic type in ASP.NET mvc 6
How to specify polymorphic type in ASP.NET mvc 6 I could use "TypeNameHandling = TypeNameHandling.Auto" in previous version of MVC. In MVC6, I have following class ``` public class BaseClass { publi...
- Modified
- 17 Dec at 03:17
Using Action dictionaries instead of switch statements
Using Action dictionaries instead of switch statements I'm just reviewing some of my old code (have some spare time), and I noticed a rather lengthy switch statement. Due to gaining new knowledge, I h...
- Modified
- 11 Jul at 01:44
How do you do polymorphism in Ruby?
How do you do polymorphism in Ruby? In C#, I can do this: ``` class Program { static void Main(string[] args) { List animals = new List(); animals.Add(new Dog()); animals.Add(new Cat()...
- Modified
- 26 Sep at 03:55
Impact analysis on subclass
Impact analysis on subclass I was modifying an overridden method of a subclass. In order to determine the impact of the change, I went through all possible scenarios and tested them. The problem is, t...
- Modified
- 12 Oct at 22:47
What uses have you found for higher-rank types in Haskell?
What uses have you found for higher-rank types in Haskell? Higher rank types look like great fun. From the [Haskell wikibook](http://en.wikibooks.org/wiki/Haskell/Polymorphism) comes this example: Now...
- Modified
- 18 Apr at 00:49
What is wrong with testing an object to see if it implements an interface?
What is wrong with testing an object to see if it implements an interface? In the comments of [this answer](https://stackoverflow.com/questions/7671121/what-is-the-name-of-this-bad-practice-anti-patte...
- Modified
- 23 May at 11:59
Is List<Dog> a subclass of List<Animal>? Why are Java generics not implicitly polymorphic?
Is List a subclass of List? Why are Java generics not implicitly polymorphic? I'm a bit confused about how Java generics handle inheritance / polymorphism. Assume the following hierarchy - (Parent) - ...
- Modified
- 20 Nov at 09:22
Calling child class method from parent
Calling child class method from parent Is it possible for the a.doStuff() method to print "B did stuff" without editing the A class? If so, how would I do that? ``` class Program { static void Main(...
- Modified
- 30 Jan at 17:42
C# inheritance. Derived class from Base class
C# inheritance. Derived class from Base class I have a base class I also have a derived class : Suppose my program created an instance of class A. some parameters were set: ``` aClassInstance.s1 = "st...
- Modified
- 25 Dec at 22:35
When to use enums, and when to replace them with a class with static members?
When to use enums, and when to replace them with a class with static members? It recently occured to me that the following (sample) enumeration... ... could be replaced with a seemingly more type-safe...
- Modified
- 2 May at 19:52
Polymorphism and casting
Polymorphism and casting I want to understand polymorphism in c# so by trying out several constructs I came up with the following case: I understand that in order to send
- Modified
- 14 Apr at 23:34
C# Generics and polymorphism: an oxymoron?
C# Generics and polymorphism: an oxymoron? I just want to confirm what I've understood about Generics in C#. This has come up in a couple code bases I've worked in where a generic base class is used t...
- Modified
- 29 Nov at 06:46
Specifying the return type of an abstract method from a Base Class according to a Sub Class
Specifying the return type of an abstract method from a Base Class according to a Sub Class I have the following structure: I want to cre
- Modified
- 18 Mar at 15:30
Method with same name and signature but different return type in C#
Method with same name and signature but different return type in C# I had an interview where I was asked the following: Question: A method with same name and signature but different return type. Is it...
- Modified
- 4 Sep at 12:52
Hiding inherited members
Hiding inherited members I'm looking for some way to effectively hide inherited members. I have a library of classes which inherit from common base classes. Some of the more recent descendant classes ...
- Modified
- 30 Apr at 10:33
Why does .net WCF Service require the Interface
Why does .net WCF Service require the Interface Unlike the asmx implementation the wcf requires for you to implement it's interface. I do not quite understand the reason behind that design. Interface ...
- Modified
- 2 Mar at 15:48
Polymorphism fundamentals
Polymorphism fundamentals I'm studying inheritance and polymorphism now and I've came across the concept that the compiler will evaluate (using reflection?) what type of object is stored in a base-typ...
- Modified
- 7 Jan at 15:39
Using the 'new' modifier in C#
Using the 'new' modifier in C# I read that the `new` modifer hides the base class method. ``` using System; class A { public void Y() { Console.WriteLine("A.Y"); } } class B : A { public n...
- Modified
- 10 May at 08:19
Why can't a static and non-static method share the same signature?
Why can't a static and non-static method share the same signature? C# provides following [signature characteristics](http://msdn.microsoft.com/en-us/library/aa691131%28v=vs.71%29.aspx) to be used whil...
- Modified
- 10 Sep at 07:13
Contrasting C# generics with Haskell parameterized types
Contrasting C# generics with Haskell parameterized types Based on some advice I found on StackOverflow, I'm digging into Haskell. I was pleased to see that Haskell's parameterized types behave very mu...
- Modified
- 20 Apr at 04:53
Creating variable of type <base class> to store <derived class> object in C#
Creating variable of type to store object in C# I'm somewhat new to programming and I have a question about classes, inheritance, and polymorphism in C#. While learning about these topics, occasionall...
- Modified
- 19 Apr at 16:16
How to call base.base.method()?
How to call base.base.method()? ``` // Cannot change source code class Base { public virtual void Say() { Console.WriteLine("Called from Base."); } } // Cannot change source code class Deriv...
- Modified
- 6 Dec at 17:14