abstract

Is it possible to make abstract classes in Python?

会有一股神秘感。 提交于 2019-11-26 13:56:19
How can I make a class or method abstract in Python? I tried redefining __new__() like so: class F: def __new__(cls): raise Exception("Unable to create an instance of abstract class %s" %cls) but now if I create a class G that inherits from F like so: class G(F): pass then I can't instantiate G either, since it calls its super class's __new__ method. Is there a better way to define an abstract class? alexvassel Use the abc module to create abstract classes. Use the abstractmethod decorator to declare a method abstract, and declare a class abstract using one of three ways, depending upon your

Precise definition of “functional interface” in Java 8

扶醉桌前 提交于 2019-11-26 13:21:42
Recently I started exploring Java 8 and I can't quite understand the concept of "functional interface" that is essential to Java's implementation of lambda expressions. There is a pretty comprehensive guide to lambda functions in Java, but I got stuck on the chapter that gives definition to the concept of functional interfaces . The definition reads: More precisely, a functional interface is defined as any interface that has exactly one abstract method. An then he proceeds to examples, one of which is Comparator interface: public interface Comparator<T> { int compare(T o1, T o2); boolean

Extend data class in Kotlin

假装没事ソ 提交于 2019-11-26 12:09:55
问题 Data classes seem to be the replacement to the old-fashioned POJOs in Java. It is quite expectable that these classes would allow for inheritance, but I can see no convenient way to extend a data class. What I need is something like this: open data class Resource (var id: Long = 0, var location: String = \"\") data class Book (var isbn: String) : Resource() The code above fails because of clash of component1() methods. Leaving data annotation in only one of classes does not do the work, too.

Abstract attribute (not property)?

谁说胖子不能爱 提交于 2019-11-26 12:08:45
问题 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

Java abstract interface

回眸只為那壹抹淺笑 提交于 2019-11-26 12:01:38
Consider an example (which compiles in java) public abstract interface Interface { public void interfacing(); public abstract boolean interfacing(boolean really); } Why is it necessary for an interface to be "declared" abstract? Is there other rules that applies with an abstract interface? Finally: If abstract is obsolete, why is it included in Java? Is there a history for abstract interface? Why is it necessary for an interface to be "declared" abstract? It's not. public abstract interface Interface { \___.__/ | '----> Neither this... public void interfacing(); public abstract boolean

Why does PHP 5.2+ disallow abstract static class methods?

左心房为你撑大大i 提交于 2019-11-26 11:43:35
After enabling strict warnings in PHP 5.2, I saw a load of strict standards warnings from a project that was originally written without strict warnings: Strict Standards : Static function Program::getSelectSQL() should not be abstract in Program.class.inc The function in question belongs to an abstract parent class Program and is declared abstract static because it should be implemented in its child classes, such as TVProgram. I did find references to this change here : Dropped abstract static class functions. Due to an oversight, PHP 5.0.x and 5.1.x allowed abstract static functions in

Abstract Method Error

只愿长相守 提交于 2019-11-26 11:21:51
问题 I am working on a project in netbeans that when I launch it using the glassfish 3.1.2.Everything works fine.But when i call the /invite url which is mapped to following method @RequestMapping(value = \"/invite\", method = RequestMethod.POST) @ExceptionHandler(GenericException.class) public ModelAndView create(@ModelAttribute(value = \"preRegister\") @Valid PreRegister preRegister, BindingResult result, HttpServletRequest request) { mav = new ModelAndView(); validator.validate(preRegister,

What is the difference between an abstract function and a virtual function?

。_饼干妹妹 提交于 2019-11-26 10:56:01
What is the difference between an abstract function and a virtual function? In which cases is it recommended to use virtual or abstract? Which one is the best approach? BFree An abstract function cannot have functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class. A virtual function , is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own

Can we instantiate an abstract class directly? [duplicate]

倖福魔咒の 提交于 2019-11-26 10:44:23
问题 This question already has answers here : Can we instantiate an abstract class? (16 answers) Closed 2 years ago . I have read we can only instantiate an abstract class by inheriting it, but we cannot instantiate it directly. However, I saw we can create an object with the type of an abstract class by calling a method of another class. For example - LocationProvider is an abstract class, and we can instantiate it by calling getProvider() function in the LocationManager class: LocationManager lm

What is the use of &#39;abstract override&#39; in C#?

不问归期 提交于 2019-11-26 09:39:08
问题 Just out of curiosity I tried overriding a abstract method in base class, and method the implementation abstract. As below: public abstract class FirstAbstract { public abstract void SomeMethod(); } public abstract class SecondAbstract : FirstAbstract { public abstract override void SomeMethod(); //?? what sense does this make? no implementaion would anyway force the derived classes to implement abstract method? } Curious to know why C# compiler allows writing \'abstract override\'. Isn\'t it