polymorphism

How to create List of open generic type of class<T>?

梦想的初衷 提交于 2020-01-19 06:24:18
问题 i am working on someone else code i need to add few things i have a class public abstract class Data<T> { } public class StringData : Data<string> { } public class DecimalData : Data<decimal> { } in my program i want to maintain list of different type of data List<Data> dataCollection=new List<Data>(); dataCollection.Add(new DecimalData()); dataCollection.Add(new stringData()); List<Data> dataCollection=new List<Data>(); at above line i am getting compiler error Using the generic type 'Data'

Double linked list in Fortran (type is not judged correctly)

人走茶凉 提交于 2020-01-17 03:40:12
问题 I would like to implement a generic double linked list in Fortran for saving codes, using PGI Fortran compiler version 12.10-0 in Mac OS X 10.8.2. Here is my prototype, including 3 files: ---> File 1: ! ---------------------------------------------------------------------------- ! Description: ! ! This module provides several basic data structures, e.g. double linked list. ! ! Authors: ! ! Li Dong <dongli@lasg.iap.ac.cn> - 2012-11-11 ! ---------------------------------------------------------

How do you pull specific objects from an arraylist?

∥☆過路亽.° 提交于 2020-01-16 18:35:10
问题 I've made an Animal superclass, Shark and Whale subclasses. What would I use to print out just the Shark objects from this arraylist? Driver: import java.util.ArrayList; public class Creator { public static void main(String[] args){ ArrayList<Animal> obj = new ArrayList<Animal>(); obj.add(new Shark("James")); obj.add(new Shark("Mike")); obj.add(new Whale("Steve")); obj.add(new Whale("Tommy")); for (Animal a: obj){ System.out.println(a.getName()); } } } 回答1: You can use the instanceof to check

Polymorphism misunderstanding / redefined virtual function not working

偶尔善良 提交于 2020-01-16 15:45:32
问题 I think I should start by simplifying my class structure so I can better explain my problem, which I suspect might just be a misunderstanding of the use of virtual. I have: class Controller{ .. virtual void InitialiseController(){ //std::cout confirms this is running } .. } class AIController : public Controller{ .. virtual void InitialiseController(){ //some logic here } .. } class ComController : public AIController{ .. virtual void InitialiseController(){ //actually the same logic as

Polymorphism misunderstanding / redefined virtual function not working

∥☆過路亽.° 提交于 2020-01-16 15:43:51
问题 I think I should start by simplifying my class structure so I can better explain my problem, which I suspect might just be a misunderstanding of the use of virtual. I have: class Controller{ .. virtual void InitialiseController(){ //std::cout confirms this is running } .. } class AIController : public Controller{ .. virtual void InitialiseController(){ //some logic here } .. } class ComController : public AIController{ .. virtual void InitialiseController(){ //actually the same logic as

Dynamic swappable Data Access Layer

匆匆过客 提交于 2020-01-14 14:41:07
问题 I'm writing a data driven WPF client. The client will typically pull data from a WCF service, which queries a SQL db, but I'd like the option to pull the data directly from SQL or other arbitrary data sources. I've come up with this design and would like to hear your opinion on whether it is the best design. First, we have some data object we'd like to extract from SQL. // The Data Object with a single property public class Customer { private string m_Name = string.Empty; public string Name {

Polymorphic ViewModel collection and rendering in MVC partial Views

折月煮酒 提交于 2020-01-14 08:07:47
问题 I'm having a problem with a polymorphic collection of ViewModels in my MVC application. I received this via a web service call and i need to iterate through them and give them their own partial view, based on the object type. public abstract class ProvinceViewModel { public string Code { get; set; } } public sealed class OntarioViewModel : ProvinceViewModel { } public sealed class QuebecViewModel : ProvinceViewModel {} In my view i am trying to iterate through them and assign a partial view.

Why is it not possible use primitive types with polymorphic return types?

爷,独闯天下 提交于 2020-01-14 07:21:17
问题 Consider the following two classes: public interface Foo<T> { public T moo(); } public class IntFoo implements Foo<Integer> { public int moo() { return 0; } } This code will produce an error at public int moo , saying that int is incompatible with the overridden method's return type Integer . Strictly speaking, this is true, since int does not directly equal Integer . However, we all know that they can be implicitly converted to each other using auto(un)boxing. What is less know is the fact

Polymorphism in Entity Framework

倖福魔咒の 提交于 2020-01-13 18:11:08
问题 The concrete classes ( BankAccount and CreditCard ) are not visible on controller. I'm stuck with this issue. I'm using the example from this site: http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx The view The CreateUser : If the CreditCard was selected it should be associated to the User class. The diagram The code UserController : [HttpPost] public ActionResult Create(User user)//The Watch

Polymorphism in Entity Framework

微笑、不失礼 提交于 2020-01-13 18:09:12
问题 The concrete classes ( BankAccount and CreditCard ) are not visible on controller. I'm stuck with this issue. I'm using the example from this site: http://weblogs.asp.net/manavi/archive/2010/12/28/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-2-table-per-type-tpt.aspx The view The CreateUser : If the CreditCard was selected it should be associated to the User class. The diagram The code UserController : [HttpPost] public ActionResult Create(User user)//The Watch