abstract

How can I force inheriting classes to implement a static method in C#?

陌路散爱 提交于 2019-11-27 13:34:51
All I want to do is make sure that child classes of the class Item implement a static method and I want this to be checked at compile time to avoid runtime errors. abstract classes with static methods don't seem to work: ERROR: A static member cannot be marked as override, virtual, or abstract public abstract class Item { public static abstract Item GetHistoricalItem(int id, DateTime pastDateTime); } public class Customer : Item { public static override Customer GetHistoricalItem(int id, DateTime pastDateTime) { return new Customer(); } } public class Address : Item { public static override

Why can't you call abstract functions from abstract classes in PHP?

不问归期 提交于 2019-11-27 13:27:07
问题 I've set up an abstract parent class, and a concrete class which extends it. Why can the parent class not call the abstract function? //foo.php <?php abstract class AbstractFoo{ abstract public static function foo(); public static function getFoo(){ return self::foo();//line 5 } } class ConcreteFoo extends AbstractFoo{ public static function foo(){ return "bar"; } } echo ConcreteFoo::getFoo(); ?> Error: Fatal error: Cannot call abstract method AbstractFoo::foo() in foo.php on line 5 回答1: This

How can I determine whether a Java class is abstract by reflection

断了今生、忘了曾经 提交于 2019-11-27 11:37:15
I am interating through classes in a Jar file and wish to find those which are not abstract. I can solve this by instantiating the classes and trapping InstantiationException but that has a performance hit as some classes have heavy startup. I can't find anything obviously like isAbstract() in the Class.java docs. It'll have abstract as one of its modifiers when you call getModifiers() on the class object. This link should help. Modifier.isAbstract( someClass.getModifiers() ); Also: http://java.sun.com/javase/6/docs/api/java/lang/reflect/Modifier.html http://java.sun.com/javase/6/docs/api/java

Abstract attribute (not property)?

坚强是说给别人听的谎言 提交于 2019-11-27 11:26:12
What's the best practice to define an abstract instance attribute, but not as a property? I would like to write something like: class AbstractFoo(metaclass=ABCMeta): @property @abstractmethod def bar(self): pass class Foo(AbstractFoo): def __init__(self): self.bar = 3 Instead of: class Foo(AbstractFoo): def __init__(self): self._bar = 3 @property def bar(self): return self._bar @bar.setter def setbar(self, bar): self._bar = bar @bar.deleter def delbar(self): del self._bar Properties are handy, but for simple attribute requiring no computation they are an overkill. This is especially important

Why give an “abstract: true” state a url?

女生的网名这么多〃 提交于 2019-11-27 11:00:28
I've be fiddling around with ui-router today in trying to better understand the scaffolding in Ionic and one thing that I noticed was that they give the abstracted state of "tabs" a url. The only times I've ever used abstract states, I used an empty string as the url and I notice that if I've ever accidentally attempted to navigate to an abstracted state (as opposed to the child state) I get the error: Cannot transition to abstract state '[insertAbstractStateHere]' edit: "Moreover, in experimenting, when I try to assign a url to my abstract state (outside of Ionic) and still render the nested

How do I create an abstract base class in JavaScript?

蓝咒 提交于 2019-11-27 10:06:36
Is it possible to simulate abstract base class in JavaScript? What is the most elegant way to do it? Say, I want to do something like: - var cat = new Animal('cat'); var dog = new Animal('dog'); cat.say(); dog.say(); It should output: 'bark', 'meow' One simple way to create an abstract class is this: /** @constructor @abstract */ var Animal = function() { if (this.constructor === Animal) { throw new Error("Can't instantiate abstract class!"); } // Animal initialization... }; /** @abstract */ Animal.prototype.say = function() { throw new Error("Abstract method!"); } The Animal "class" and the

abstract class and anonymous class [duplicate]

你。 提交于 2019-11-27 08:20:53
问题 This question already has an answer here: Creating the instance of abstract class or anonymous class 8 answers abstract class Two { Two() { System.out.println("Two()"); } Two(String s) { System.out.println("Two(String"); } abstract int display(); } class One { public Two two(String s) { return new Two() { public int display() { System.out.println("display()"); return 1; } }; } } class Ajay { public static void main(String ...strings ){ One one=new One(); Two two=one.two("ajay"); System.out

Why can't we instantiate an interface or an abstract class in java without an anonymous class method?

自闭症网瘾萝莉.ら 提交于 2019-11-27 05:47:53
问题 I know, we can not instantiate either an interface or an abstract class in java except using anonymous class method but what is the reason behind it? 回答1: You can't instantiate an interface or an abstract class because it would defy the object oriented model. Interfaces represent contracts - the promise that the implementer of an interface will be able to do all these things, fulfill the contract. Abstract classes are a similar idea, in that they represent an unfulfilled contract, a promise

Class is not Abstract and does not Override error in Java

こ雲淡風輕ζ 提交于 2019-11-27 05:25:41
I am getting a compile time error with Java: MyClass is not abstract and does not override abstract method onClassicControllerRemovedEvent( wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent) in wiiusejevents.utils.WiimoteListener) Here is the class: import wiiusej.WiiUseApiManager; import wiiusej.Wiimote; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; import wiiusej.wiiusejevents

C#, implement 'static abstract' like methods

心不动则不痛 提交于 2019-11-27 04:39:58
问题 I recently ran into a problem where it seems I need a 'static abstract' method. I know why it is impossible, but how can I work around this limitation? For example I have an abstract class which has a description string. Since this string is common for all instances, it is marked as static, but I want to require that all classes derived from this class provide their own Description property so I marked it as abstract: abstract class AbstractBase { ... public static abstract string Description