abstract

boost serialize polymorphic class

喜夏-厌秋 提交于 2020-01-02 09:13:12
问题 With the following example I attempting to learn a few new to me concepts. abstraction polymorphic classes factory programming. boost serialization The nuances of how pointers behave are still something I am working to figure out. Here is a small program that I have written to show you the issue I am struggling to understand. When I unserialize the polymorphic object below I only get an object created from the default constructor. TodoFactory::retrieveATodo is not recreating the object from

Creating an abstract class that implements multiple interfaces in c#

荒凉一梦 提交于 2020-01-02 03:37:09
问题 I'd like to create an abstract class in c#, that "inherits" from different interfaces, but leaves the concrete implementation to the subclass. The compiler however complains, that the class doesnt implement the methods specified in the interfaces. I'm used to Java where this always worked, so I'm not sure how it is supposed to work in c#. Anyway, this is my code: public abstract class MyClass : IDisposable, IPartImportsSatisfiedNotification { private string name; public MyClass(string name) {

Adding setters to properties in overrides

狂风中的少年 提交于 2020-01-02 00:32:08
问题 Why is it allowed to change the visibility and existence of getters or setters in a property when implementing an interface? interface IFoo { string Bar { get; } } class RealFoo : IFoo { public RealFoo(string bar) { this.Bar = bar; } public string Bar { get; private set; } } class StubFoo : IFoo { public string Bar { get; set; } } ...and not legal to do the same when implementing an abstract class? abstract class AbstractFoo : IFoo { public abstract string Bar { get; } } class RealFoo :

Adding setters to properties in overrides

只谈情不闲聊 提交于 2020-01-02 00:32:05
问题 Why is it allowed to change the visibility and existence of getters or setters in a property when implementing an interface? interface IFoo { string Bar { get; } } class RealFoo : IFoo { public RealFoo(string bar) { this.Bar = bar; } public string Bar { get; private set; } } class StubFoo : IFoo { public string Bar { get; set; } } ...and not legal to do the same when implementing an abstract class? abstract class AbstractFoo : IFoo { public abstract string Bar { get; } } class RealFoo :

Abstract enum in c#

南笙酒味 提交于 2020-01-01 15:07:40
问题 Is there a way to make a ( protected ) enum abstract in C#? Example of base class: protected abstract enum commands{}; //CS0106 protected abstract void useCommands(commands meh); This does not compile, since " abstract is not valid for this item". Is there a working way to achive the desired behaviour? 回答1: All enums must derive from System.Enum All enums are value types and hence sealed. Because of above these two rules, you cannot inherit enums. 回答2: enum is a keyword , not a class name : /

How to force implementation of a method in subclass without using abstract?

和自甴很熟 提交于 2020-01-01 07:45:12
问题 I want to force subclass to implement an implemented method of my mother class. I look this Java - Force implementation of an implemented method but i can't convert my mother class to an abstract class. public class myMotherClass { myMethod { ...some code .. } } public class myClass extends myMotherClass { myMethod { ... other code ... } } So, in this exemple, I want to force myClass implement myMethod. Sorry for my english... 回答1: You can not force a subclass to override a method. You can

Scala's sealed abstract vs abstract class

*爱你&永不变心* 提交于 2019-12-31 08:10:56
问题 What is the difference between sealed abstract and abstract Scala class? 回答1: The difference is that all subclasses of a sealed class (whether it's abstract or not) must be in the same file as the sealed class. 回答2: As answered, all directly inheriting subclasses of a sealed class (abstract or not) must be in the same file. A practical consequence of this is that the compiler can warn if the pattern match is incomplete. For instance: sealed abstract class Tree case class Node(left: Tree,

Assertions in abstract superclass scala creating NPE

走远了吗. 提交于 2019-12-31 03:06:08
问题 The following code, when entered in REPL abstract class A { val aSet: Set[Int]; require(aSet.contains(3)) } class B extends A { val aSet = Set(4,5,6) } new B() gives a null point exception, rather than an invariant failure. What would be the best idiom to solve this problem? Similar questions: Code Contracts: Invariants in abstract class Private constructor in abstract class Scala? and also online commentary: https://gist.github.com/jkpl/4932e8730c1810261381851b13dfd29d 回答1: When you declare

How do i make an abstract class work with JAXB

点点圈 提交于 2019-12-30 06:31:07
问题 Dear fellow java coders, I have used an example from http://www.vogella.com/articles/JAXB/article.html for JAXB XML usage for my 3 classes, UserStorage, User, and UserTest it works fine, but it's just the unmarchialing of JAXBContext context = JAXBContext.newInstance(UserStorage.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); the User class is ABSTRACT!, so it throws an Exception in thread "main" javax.xml.bind

C# abstract class static field inheritance

不羁岁月 提交于 2019-12-30 02:48:06
问题 I feel like I skipped a C# class or two, but here's my dilemma: I have an abstract class from which I derive multiple child classes. I know for sure that for each of the child classes I will have a constructor that needs a certain static object as a model and this object will be different for each of the child classes. My first approach was to make a public static object in the abstract parent class and then, before I start creating any instances of the child classes, I would modify it for