polymorphism

Reintroducing functions in Delphi

笑着哭i 提交于 2019-12-17 15:24:59
问题 What was the motivation for having the reintroduce keyword in Delphi? If you have a child class that contains a function with the same name as a virtual function in the parent class and it is not declared with the override modifier then it is a compile error. Adding the reintroduce modifier in such situations fixes the error, but I have never grasped the reasoning for the compile error. 回答1: If you declare a method in a descendant class that has the same name as a method in an ancestor class

Laravel: Returning the namespaced owner of a polymorphic relation

十年热恋 提交于 2019-12-17 15:23:54
问题 I can find a number of discussions regarding this but no clear solution. Here are two links, although I will cover everything in my own question here. Github Issues Laravel.io discussion Simple Explanation This is a simple explanation of my problem for anyone already familiar with Laravel's polymorphic relationships. When using $morphClass, the contents of $morphClass which is saved in the database as the morph "type" is used for the classname when trying to find the owner of a polymorphic

Why can't I do polymorphism with normal variables?

牧云@^-^@ 提交于 2019-12-17 14:50:32
问题 I'm a Java programmer and recently started studying C++. I'm confused by something. I understand that in C++, to achieve polymorphic behavior you have to use either pointers or references. For example, consider a class Shape with an implemented method getArea() . It has several subclasses, each overriding getArea() differently. Than consider the following function: void printArea(Shape* shape){ cout << shape->getArea(); } The function calls the correct getArea() implementation, based on the

Double dispatch/multimethods in C++

扶醉桌前 提交于 2019-12-17 11:51:25
问题 I have a question on C++ double dispatch. In the code below, I want the results from the second set to match the results from the first set. I don't know the actual type (unless I try dynamic_cast) but I do know that the object inherited from the BaseClass type. What is the most efficient (performance-wise) way to accomplish this? After googling around for a while I found out about double dispatch and the loki multimethods. The problem I have with the Shape examples is that in my application,

Hiding inherited members

戏子无情 提交于 2019-12-17 11:18:07
问题 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 inherit dependency properties which have become vestigial and can be a little confusing when using IntelliSense or using the classes in a visual designer. These classes are all controls that are written to be compiled for either WPF or Silverlight 2.0. I know about ICustomTypeDescriptor and ICustomPropertyProvider , but

JSON serialization of array with polymorphic objects

落爺英雄遲暮 提交于 2019-12-17 10:46:29
问题 Is it possible with .NET standard JavascriptSerializer/JsonDataContractSerializer or external parsers, to serialize objects array using a wrapper approach including the object type? For example, to generate this JSON from a List: [{ 'dog': { ...dog properties... } }, { 'cat': { ...cat properties... } }] instead of typical: [{ ...dog properties... }, { ...cat properties... }] This is doable in Java with Jackson using JsonTypeInfo.As.WRAPPER_OBJECT attribute. 回答1: Json.NET has a neat solution

Setting up a polymorphic has_many :through relationship

删除回忆录丶 提交于 2019-12-17 10:15:12
问题 rails g model Article name:string rails g model Category name:string rails g model Tag name:string taggable_id:integer taggable_type:string category_id:integer I have created my models as shown in the preceding code. Articles will be one of many models which can have tags. The category model will contain all categories which may be assigned. The tag model will be a polymorphic join-table which represents tagged relationships. class Article < ActiveRecord::Base has_many :tags, :as => :taggable

Haskell: How to create most generic function possible that applies a function to tuple items

好久不见. 提交于 2019-12-17 09:56:28
问题 This is a personal exercise to understand the limits of Haskell's type system a little better. I want to create the most generic function I can that applies some function to each entry in a 2 entry tuple eg: applyToTuple fn (a,b) = (fn a, fn b) I am trying to make this function work in each of the following cases: (1) applyToTuple length ([1,2,3] "hello") (2) applyToTuple show ((2 :: Double), 'c') (3) applyToTuple (+5) (10 :: Int, 2.3 :: Float) So for length the items in the pair must be

Jackson JsonTypeInfo.As.EXTERNAL_PROPERTY doesn't work as expected

六月ゝ 毕业季﹏ 提交于 2019-12-17 09:48:01
问题 I am using Jackson to parse JSON that I have no control over. The JSON looks like this: { "status":"0" "type":"type1" "info": { // additional fields } } My class looks like this public class Response { private String status; private String type; private Info info } The subclass of Info that I use depends on the type property, so my mapping for info is @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes(value = { @JsonSubTypes

Jackson JsonTypeInfo.As.EXTERNAL_PROPERTY doesn't work as expected

被刻印的时光 ゝ 提交于 2019-12-17 09:47:02
问题 I am using Jackson to parse JSON that I have no control over. The JSON looks like this: { "status":"0" "type":"type1" "info": { // additional fields } } My class looks like this public class Response { private String status; private String type; private Info info } The subclass of Info that I use depends on the type property, so my mapping for info is @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type") @JsonSubTypes(value = { @JsonSubTypes