polymorphism

Polymorphism in binding?

时间秒杀一切 提交于 2019-12-11 14:13:11
问题 I have a POCO objects (public class with lots of public fields). public class Poco { public string name1; public string name2; public bool isName1Used; } Now i need to render a list of objects names, but with one condition: depending on bool, should be used name1 or name2. So, i made inherited class and add some functionality there public class Item : Poco { public string Name { get { return isName1Used ? name1 : name2; } } How can i now say to binding engine that it should bind to the Name?

How to create custom classes that inherit from sqlalchemy models in external library

自古美人都是妖i 提交于 2019-12-11 14:02:44
问题 Rather than creating mixin classes that models inherit from, I have a use case that requires me to configure classes the other way around. The classes that would normally be mixin classes need to be the classes that inherit from the models as well as the class that model objects are created from. This is because the models and the mapper configurations are in an external library from the main repository. I need to pass in the host for the engine from the main repository to the models library

What should the TwoDimensionalShape Class contain?

时光怂恿深爱的人放手 提交于 2019-12-11 13:54:37
问题 I am trying to do an exercise with polymorphism in C++ to calculate the area and volume of the figures int the following hierarchy Shape TwoDimensionalShape ThreeDimensional Circle Square Triangle Sphere Cube I declared a virtual function getArea and getVolume in the Shape class, and for example in the Circle class the function is: double Circle::getArea() const { return 3.14*radius*radius; } where radius is private in the circle class. But I am stuck a little on what should I include in the

Ruby on Rails has_many and polymorphism

天涯浪子 提交于 2019-12-11 13:54:14
问题 I'm new to Ruby on Rails and I'm trying to understand abstract class. Maybe I still have in mind Java structure... I followed many tutorials and there is still things I'd need to understand. Let's say we want to build a contact book. In this address book, we have people and companies. class Address < ActiveRecord::Base belongs_to :addressable, :polymorphic => true end class Person < ActiveRecord::Base has_one :address, :as => :addressable end class Company < ActiveRecord::Base has_one

Generically comparing objects in an inheritance hierarchy in c++

寵の児 提交于 2019-12-11 13:48:03
问题 I am planning to write a multimap like this std::multimap <key, base_ptr> mymap; And I would like to be able to store pointers of many derived classes (say Der1 , Der2 ) which derive from the base. Now when I am trying to insert an object into the map, I first do a lookup on the key and then I need to compare if the object is EQUIVALENT (does not have to be the same object hence not doing a pointer comparison) to the one at that location. So for this lets say I override the == operator or

map of derived classes

自作多情 提交于 2019-12-11 13:09:20
问题 I have a base class class Person{ public: Person(string name , int age ){ this -> name = name; this -> age = age; } virtual void getInfo(){ cout << "Person " << name << " " << age; } void add(string name , const Person & b){ a[name] = b } protected: string name; int age; map<string , Person > a; }; That contains map of object type Person. I want to push various derived classes into that map e.g Derived class class Kid : public Person{ public: Kid(string name, int age):Person(name,age){};

XSD abstract types and polymorphism

半世苍凉 提交于 2019-12-11 12:58:54
问题 I'm trying to model the following situation into an XSD schema, but kinda stuck and not sure if XSD supports what I'm trying to achieve. I have two complex elements, which both should be abstract: Session SessionResult Their relationship: one Session can contain zero or more SessionResults Then I have these other complex types (non-abstract): RaceSession (inherits from Session) TimedSession (inherits from Session) RaceSessionResult (inherits from SessionResult) TimedSessionResult (inherits

new vs override keywords

五迷三道 提交于 2019-12-11 12:53:55
问题 I've got a question concerning polymorphic methods. I've got two classes: the base class with the non-virtual method Foo( ) which calls its virtual method Foo (int i) (like this: Foo() {Foo(1);}) and the derived class which overrides method Foo(int i) . If I call Foo() method of an instance of the derived class the walkthrough is as the following: base Foo() -> override Foo(int i) . But if I change override method to new the walkthrough is as the following: base Foo -> base Foo(int i) . It

methods overriding and overloading

限于喜欢 提交于 2019-12-11 12:49:30
问题 can i overload or override methods just by using different return value ? is virtual matter in thie case ? for example : class A{ virtual int Foo(); // is this scenario possible with/without the keyword virtual } class B : public A { virtual double Foo(); } A* Base = new B(); int i = Base->Foo(); // will this just convert double to int ? and regarding overloading : class A{ virtual int Foo(); virtual float Foo(); // is this possible ? int Goo(); float Goo(); // or maybe this ? } Class B{

WCF DataContracts and Polymorphism

戏子无情 提交于 2019-12-11 12:28:24
问题 Here's what I want to do. This should (theoretically) be very simple. Say I have a WCF service with the following code (bare bones functionality): <DataContract()> Public Class BaseObj <DataMember()> Public ID As Integer End Class <DataContract()> Public Class TestObj1 Inherits BaseObj Public Sub New(ByVal idval As Integer) ID = idval End Sub End Class <DataContract()> Public Class TestObj2 Inherits BaseObj Public Sub New(ByVal idval As Integer) ID = idval End Sub <DataMember()> Public