abstract

How to deserialize concrete implementation of abstract class from XML

心已入冬 提交于 2019-12-01 19:08:12
I have an abstract class with a couple of concrete implementations. This needs serializing to XML in order to send to another system - this is working fine. However, I also need to be able to deserialize the same XML structure back. No matter what I try, I don't seem to be able to do this. My class structure is as below: Abstract Class: [XmlIncludeAttribute(typeof(ConcreteFooOne))] [XmlIncludeAttribute(typeof(ConcreteFooTwo))] [XmlIncludeAttribute(typeof(ConcreteFooThree))] [XmlRoot(ElementName = "FooData", Namespace="http://foo.bar")] public abstract partial class AbstractFoo { // Some

Overriding an abstract method with a virtual one

﹥>﹥吖頭↗ 提交于 2019-12-01 17:52:11
I'm trying to override an abstract method in an abstract class with a virtual method in a child class. I (assumed until now?) understand the difference between abstract and virtual methods. Obviously I'm not able to do it but my question is... why? Based on the accepted answer here and the following scenario, I just don't see the problem: public abstract class TopLevelParent { protected abstract void TheAbstractMethod(); } public class FirstLevelChild1 : TopLevelParent { protected override void TheAbstractMethod() { } } public class FirstLevelChild2 : TopLevelParent { protected virtual

Access Level to certain class must be public error in PHP

你离开我真会死。 提交于 2019-12-01 16:32:47
I created this class <?php abstract class Validator{ public $_errors = array(); abstract public function isValid($input); public function _addErrors($message){ $this->_errors = $message; } public function getErrors(){ return $this->_errors; } public function getMessage(){ return $this->message; } } class Validator_NoSpaces extends Validator{ public function __construct($value){ $this->isValid($value); } public function isValid($value){ if (preg_match('/\s/', $value)){ $this->_addErrors("Spaces are not allowed"); return false; } return true; } } class Validator_MinimumLength extends Validator{

Access Level to certain class must be public error in PHP

﹥>﹥吖頭↗ 提交于 2019-12-01 15:41:54
问题 I created this class <?php abstract class Validator{ public $_errors = array(); abstract public function isValid($input); public function _addErrors($message){ $this->_errors = $message; } public function getErrors(){ return $this->_errors; } public function getMessage(){ return $this->message; } } class Validator_NoSpaces extends Validator{ public function __construct($value){ $this->isValid($value); } public function isValid($value){ if (preg_match('/\s/', $value)){ $this->_addErrors(

ForeignKey field related to abstract model in Django

送分小仙女□ 提交于 2019-12-01 15:16:45
I have this model: class BaseModel(models.Model): .... class Meta: abstract = True class ModelA(BaseModel): .... class ModelB(BaseModel): .... class MyExtModel(models.Model) myfield = models.ForeignKey(BaseModel) But this is not correct because I have BaseModel like Abstract . Infact I have an error when I try makemigration command. The error is: ERRORS: myapp.MyExtModel.myfield: (fields.E300) Field defines a relation with model 'BaseModel', which is either not installed, or is abstract. Is there a way to use an abstract base model? I also tried to use: myfield = models.ForeignKey(BaseModel,

ForeignKey field related to abstract model in Django

时间秒杀一切 提交于 2019-12-01 14:14:37
问题 I have this model: class BaseModel(models.Model): .... class Meta: abstract = True class ModelA(BaseModel): .... class ModelB(BaseModel): .... class MyExtModel(models.Model) myfield = models.ForeignKey(BaseModel) But this is not correct because I have BaseModel like Abstract . Infact I have an error when I try makemigration command. The error is: ERRORS: myapp.MyExtModel.myfield: (fields.E300) Field defines a relation with model 'BaseModel', which is either not installed, or is abstract. Is

Is there a way to make sure classes implementing an Interface implement static methods?

橙三吉。 提交于 2019-12-01 13:46:05
问题 First of all, I read erickson's useful reply to "Why can’t I define a static method in a Java interface?". This question is not about the "why" but about the "how then?". Edit: my original example was ill-posed, but I'll leave it below. While I am now convinced that in most cases what I want to do is overkill, there is one scenario where it could be needed: I'll take the ParametricFunction example again. Now let's take a complicated function, like the Bessel functions, where a lookup-table is

Naming convention for GoF Factory?

 ̄綄美尐妖づ 提交于 2019-12-01 11:49:37
This pattern uses an abstract factory, and then an implementation of the factory. I am sure there is a standard naming convention for these two classes, but I don't know what it is. For example: public abstract class ChocolateFactory { }; public class MyChocolateFactory { } : ChocolateFactory What's the standard convention here? I'm thinking either ChocolateFactoryBase, or ConcreteChocolateFactory, but perhaps there is something else (much like Enums tend to be suffixed with Enum, e.g. PetTypeEnum so that you can do PetTypeEnum PetType; Hopefully this isn't subjective. The question and the

Naming convention for GoF Factory?

泪湿孤枕 提交于 2019-12-01 09:26:02
问题 This pattern uses an abstract factory, and then an implementation of the factory. I am sure there is a standard naming convention for these two classes, but I don't know what it is. For example: public abstract class ChocolateFactory { }; public class MyChocolateFactory { } : ChocolateFactory What's the standard convention here? I'm thinking either ChocolateFactoryBase, or ConcreteChocolateFactory, but perhaps there is something else (much like Enums tend to be suffixed with Enum, e.g.

ptr_map and pointer

久未见 提交于 2019-12-01 08:19:11
I'm using ptr_map from boost for storing objects derived from some base abstract type. class Entity { virtual void foo() = 0; }; class Entity1 : public Entity {}; class Entity2 : public Entity {}; boost::ptr_map<string, Entity> someMap; // We could store pointers for abstract type Inserting works great: someMap.insert("someKey", new Entity1()); someMap.insert("someKey", new Entity2()); But not returning from map: template<typename EntityType> EntityType *GetEntity(const string &entityName) { return dynamic_cast<EntityType*>(&someMap[entityName]); } GetEntity<Entity1>(entityName); Now the