inheritance

Doctrine inheritance for entities common fields

[亡魂溺海] 提交于 2020-01-15 08:28:50
问题 I'm using Zend Framework 3 and Doctrine ORM for my web project. I have several modules in my application ( User , Stock , Sales ) and some entity models on each Module: User module entities: User , Account , etc.. Stock module entities: SKU , StockLevel , etc.. Sales module entities: Invoice , PaymentMethod , etc.. By default all entities has common fields, things like: creationDateTime : Date/time of creation creationUser : User who create the entity lastChangeDateTime : Date/time of last

Serialize inherited classes using protobuf-net

血红的双手。 提交于 2020-01-15 05:58:29
问题 I have a problem serializing derived classes using protobuf-net. I don't know if it is because it is not supported, or I am doing something wrong. I have a generic base class (which I can serialize directly) and then i make a specialization of this, but this one I can't serialize. The following is the code for the two classes and a example of usage. Am i doing something wrong? Edit Added restriction to the generic types Base [ProtoBuf.ProtoContract] public class Base<TKey, TValue> where TKey

Dictionary compatibility of base class vs. subclass values

痴心易碎 提交于 2020-01-15 05:35:16
问题 I have an object hierarchy: MyObject +Variable +etc. (So MyObject is the base class, and Variable is one of the subclasses). I have the dictionaries for the specific types private ConcurrentDictionary<string, Variable> variables = new ConcurrentDictionary<string, Variable>(); etc. and I would like to put all the various lists in one high level dictionary, where I would find all the specific lists: private Dictionary<Type, ConcurrentDictionary<string, MyObject>> objects = new Dictionary<Type,

Inheriting child-specific method from parent

北慕城南 提交于 2020-01-15 03:57:06
问题 I don't know if this is at all possible, but I was thinking of something in Java: If I have an abstract parent class, I can do this: public ParentClass add(ParentClass a, ParentClass b); If ParentClass then has a child and I want to override this method, the child class will still have a ParentClass add(ParentClass, ParentClass) method. Is there a way to make the parent function derive itself to each child? I don't know if I'm wording it right, but something like this: // ParentClass.java

Inheritance: Internal Class vs. Internal Interface

偶尔善良 提交于 2020-01-14 18:50:01
问题 While expressing concern with preventing exposure of base classes, I learned (through testing) that a public class cannot inherit from an internal class; however, a public class can inherit from an internal interface. I am truly curious as to why this is possible. I believe it could be due to one of (or any combination of) the following: An interface simply contains signatures that must be implemented. A class may have properties, methods, etc. that can be accessed via the derived type. A

Inheritance: Internal Class vs. Internal Interface

≡放荡痞女 提交于 2020-01-14 18:49:16
问题 While expressing concern with preventing exposure of base classes, I learned (through testing) that a public class cannot inherit from an internal class; however, a public class can inherit from an internal interface. I am truly curious as to why this is possible. I believe it could be due to one of (or any combination of) the following: An interface simply contains signatures that must be implemented. A class may have properties, methods, etc. that can be accessed via the derived type. A

How to find types that are direct descendants of a base class?

落爺英雄遲暮 提交于 2020-01-14 18:44:12
问题 I need to get all types of an assembly that inherits some base class but only the first descendants. For instance if I have: class Base { } class FirstClass : Base { } class SecondClass : FirstClass { } Now var directOnes = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Base))); should return only FirstClass and not SecondClass . Is there a way to find out? 回答1: Instead of IsSubclassOf() you can use Type.BaseType e.g. var directOnes = assembly.GetTypes().Where(t => t.BaseType == (typeof

Avoiding “Pure Virtual Function Call” in Derived Class C++

旧时模样 提交于 2020-01-14 14:30:35
问题 I'm reasonably new to C++ so I'd like to apologize if the level of this question is a little below the usual standards here - I'm trying to get several classes to inherit from a base class which has a virtual function definition, then I'd like to create an array of MainClass* which can include all of the derived classes in order to output the derived + defined virtual function. I receive the Error "R6025: pure virtual function call" - I don't know why, I was assuming that - when called - the

Processing parameters before calling the base constructor

孤街浪徒 提交于 2020-01-14 12:56:46
问题 is it possible to process parameters before passing them into a base constructor? As in: A --> B Where A is an abstract class and B is the child class. A's constructor is like so: Protected A (MyObject myObject) B's constructor is like so: Public B (string objectName) I want it to be something like this Public B (String objectName) : base (MyObject myObject) { myObject = new MyObject (objectName); } 回答1: If you want to do something non-trivial (that doesn't fit naturally into a single

Tricky question about generics, inheritance and chaining

戏子无情 提交于 2020-01-14 10:25:11
问题 For context - read this. Problem: class Program { static void Main() { var b = new bar(); b.buzz().fizz().buzz().fizz(); //cool // ^FAIL!!!...<------------------------------------ Console.ReadLine(); } } public class foo { public foo fizz() { return this; } } public class bar : foo { public bar buzz() { return this; } } Solution: class Program { static void Main() { var b = new bar(); b.buzz().fizz().buzz().fizz(); //cool stuff Console.ReadKey(); } } public static class fooExtensions { public