abstract-class

Why use Abstract Base Classes in Python?

情到浓时终转凉″ 提交于 2019-12-17 03:47:07
问题 Because I am used to the old ways of duck typing in Python, I fail to understand the need for ABC (abstract base classes). The help is good on how to use them. I tried to read the rationale in the PEP, but it went over my head. If I was looking for a mutable sequence container, I would check for __setitem__ , or more likely try to use it (EAFP). I haven't come across a real life use for the numbers module, which does use ABCs, but that is the closest I have to understanding. Can anyone

Why use Abstract Base Classes in Python?

末鹿安然 提交于 2019-12-17 03:46:54
问题 Because I am used to the old ways of duck typing in Python, I fail to understand the need for ABC (abstract base classes). The help is good on how to use them. I tried to read the rationale in the PEP, but it went over my head. If I was looking for a mutable sequence container, I would check for __setitem__ , or more likely try to use it (EAFP). I haven't come across a real life use for the numbers module, which does use ABCs, but that is the closest I have to understanding. Can anyone

How to implement an abstract class in ruby?

北慕城南 提交于 2019-12-17 03:46:41
问题 I know there is no concept of abstract class in ruby. But if at all it needs to be implemented, how to go about it? I tried something like... class A def self.new raise 'Doh! You are trying to write Java in Ruby!' end end class B < A ... ... end But when I try to instantiate B, it is internally going to call A.new which is going to raise the exception. Also, modules cannot be instantiated but they cannot be inherited too. making the new method private will also not work. Any pointers? 回答1: I

Abstract class in Java

不想你离开。 提交于 2019-12-16 20:05:21
问题 What is an "abstract class" in Java? 回答1: An abstract class is a class which cannot be instantiated. An abstract class is used by creating an inheriting subclass that can be instantiated. An abstract class does a few things for the inheriting subclass: Define methods which can be used by the inheriting subclass. Define abstract methods which the inheriting subclass must implement. Provide a common interface which allows the subclass to be interchanged with all other subclasses. Here's an

Calling methods of class derived from an abstract class [C++]

三世轮回 提交于 2019-12-14 03:57:17
问题 You'll have to forgive me if this is a really basic question; I haven't used C++ this much in a long time so I've forgotten how a lot of it works. Anyway, I have a base class and a couple derived classes like this (super oversimplified, but the gist is the same): class Base { public: Base () { } int SomeFunction (int x, int y); // abstract definition }; class Derived1 : public Base { public: Derived1() : Base() { } int SomeFunction (int x, int y) { // actual implementation return 4; } };

Ninject: GetAll instances that inherit from the same abstract class

☆樱花仙子☆ 提交于 2019-12-14 03:20:34
问题 Is it possible for Ninject to get all instances that inherit from a specific Abstract Class? For example, I have the following Abstract Class. public abstract class MyAbstractClass { } Then I have the following two derived classes that both inherit from the same abstract class. public class MyDerivedClass1 : MyAbstractClass { } public class MyDerivedClass2 : MyAbstractClass { } Now I am going to bind both derived classes with the Kernel because I want them to be in singleton scope. _kernel =

How to resolve abstract static method design issue?

天大地大妈咪最大 提交于 2019-12-14 03:17:36
问题 I have several queues that all extend a Queue class. I want to do a Queue manger base class to handle adding to the queue (and other operations). If you take a look at the following code, I created a base class called QueueManger that has a static method called add() that will get 'Queue' and add a variable to it. I want to make getQueue() (called in add() ) abstract because I want to force other classes to provide their own implementation of the 'Queue'. The issue is I can't declare abstract

Empty virtual method on base class VS abstract methods [closed]

我的梦境 提交于 2019-12-14 03:09:24
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I couldn't find a question that was not too specific to some case, so I'll try to make this very generic. We need an extractor base class to a set of documents, for example. Each document has its specific properties, but they're ultimately documents. So we want to provide

can we create object of abstract class?

十年热恋 提交于 2019-12-14 02:05:00
问题 I am just confused about abstract class concept. Please clear my doubt. Definition of Abstract class says we can not create object of such class, then what we called like A a=new A(){ } . Example is below public abstract class AbstractTest { public abstract void onClick(); public void testClick(){ } } public class A { AbstractTest test = new AbstractTest(){ @Override public void onClick() { } }; } Then test is a object or what? 回答1: test is an object of an anonymous concrete sub-class of

Inheriting abstract classes with abstract properties

亡梦爱人 提交于 2019-12-14 02:00:04
问题 I have base class with abstract properties. I want all inheriting classes to override abstract properties. Example: public class Person { public string Name{get;set;} public string LastName{get;set;} } public class Employee : Person { public string WorkPhone{get;set;} } public abstract class MyBase { public abstract Person Someone {get;set;} } public class TestClass : MyBase { public override Employee Someone{get;set;} //this is not working } Base class has Someone property with Person type.