abstract

Creating an abstract class that implements multiple interfaces in c#

[亡魂溺海] 提交于 2019-12-05 06:07:55
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) { this.name = name; } } Add abstract methods: public interface IPartImportsSatisfiedNotification { void

c++ abstract class with nested class. derived class and nested class

∥☆過路亽.° 提交于 2019-12-05 01:57:45
I have the task to write own containers Linked_list and Array_list . I have one interface for them: typedef int value_type; class Container { public: class Iterator { public: Iterator(); Iterator(value_type* other); Iterator(const Iterator& other); Iterator& operator=(const Iterator& other); ... }; Container(); Container(const Container& other); ~Container(); virtual value_type& front() const=0; virtual value_type& back() const=0; virtual Iterator begin() const=0; // ... }; I did derived classes Linked_list and Array_list: class Linked_list:public Container { public: long int cur_size; List

Abstract Class in Delphi

这一生的挚爱 提交于 2019-12-04 23:11:04
I am using a component suite which has many abstract classes. Now I want to apply polymorphism but I am getting Error Abstract Class when I create my object. Should I override all methods which are virtual even if I don't need it? Are there any workaround or solution? In order to make an instance of a class, you need to override all methods that are declared as virtual abstract. Even if you don't use them. If you really want a work around, you can use empty methods. But I won't recommend that. And to add some more information on the subject: A method is abstract if it is declared with virtual

Semantics of abstract traits in Scala

自古美人都是妖i 提交于 2019-12-04 22:57:31
I am wondering what the semantics of using the abstract keyword in combination with a trait is. If the trait does not define any abstract methods, the abstract keyword does not prevent me from creating an instance: scala> abstract trait T defined trait T scala> new T{} res0: java.lang.Object with T = $anon$1@12cd927d On the other hand, if the trait does define an abstract method, I cannot create an instance (without implementing this method of course) no matter if the abstract keyword is present or not: scala> abstract trait T { def foo : Unit } defined trait T scala> new T{} <console>:9:

Adding setters to properties in overrides

一曲冷凌霜 提交于 2019-12-04 22:53:50
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 : AbstractFoo { public RealFoo(string bar) { this.Bar = bar; } // Cannot override because 'Bar' does not have

Why can't you have a protected abstract class in Java?

时光毁灭记忆、已成空白 提交于 2019-12-04 18:50:39
问题 I have an abstract class which looks like: abstract class AbstractFoo implements Bar { //Code goes here } However when I try to make AbstractFoo protected I get an error compile time error complaining that it is an illegal modifier. protected abstract class AbstractFoo implements Bar { //Code goes here } Why can't you have a protected abstract class within Java? EDIT: I should probably mention that this is not vanilla Java and is actually Blackberry / J2ME. 回答1: As many others have noted, the

How can abstract classes have references but not objects?

廉价感情. 提交于 2019-12-04 18:25:19
问题 Note that you cannot construct an object of an abstract class, but you can still have an object reference whose type is an abstract class. Of course, the actual object to which it refers must be an instance of a concrete subclass: Account anAccount; // OK anAccount = new Account(); // Error—Account is abstract anAccount = new SavingsAccount(); // OK anAccount = null; // OK Not understanding why you can have an object reference to an abstract class... 回答1: When you have an object reference

How do I initialize a Graphics object in Java?

浪子不回头ぞ 提交于 2019-12-04 11:01:55
this is the code: import java.awt.*; import java.applet.*; public class anim1 extends Applet{ public void paint (Graphics g) { g.drawString("",400,300); } public static void main(String ad[]) { anim1 a=new anim1(); Graphics g1; a.paint(g1); } } It says that g1 is not initialized. But how do I initialize an abstract class? Well there are two issues here 1: Graphics g1; a.paint(g1); And you are getting the error that G1 is not initialized. That's because the variable g1 is never set to anything, and that causes a compile error. To get the code to compile, you would need to, at the very least do

How to access Abstract superclass instance variable

限于喜欢 提交于 2019-12-04 06:56:17
问题 So I have two classes: Property and Houses . Property is the abstract super class and Houses is its subclass. Here is the code for Property public abstract class Property{ String pCode; double value; int year; public Property(String pCode, double value , int year){ this.pCode = pCode; this.value = value; this.year = year; } public Property(){ pCode = ""; value = 0; year = 0; } public abstract void depreciation(); //Accessors private String getCode(){ return pCode; } private double getValue(){

How to deserialize concrete implementation of abstract class from XML

萝らか妹 提交于 2019-12-04 03:57:03
问题 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