abstract

How do I create an abstract base class in JavaScript?

旧街凉风 提交于 2019-12-17 10:07:48
问题 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' 回答1: 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... }; /**

Interface or abstract class?

自作多情 提交于 2019-12-17 03:20:09
问题 For my new Pet-Project I have a question for design, that is decided already, but I want some other opinions on that too. I have two classes (simplified): class MyObject { string name {get;set;} enum relation {get;set;} int value {get;set;} } class MyObjectGroup { string name {get;set;} enum relation {get;set;} int value {get;set;} List<MyObject> myobjects {get;set;} } Later in the Project MyObjectGroup and MyObject should be used equally. For this I could go two ways: Create an interface:

Why does PHP 5.2+ disallow abstract static class methods?

若如初见. 提交于 2019-12-17 02:21:11
问题 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

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

送分小仙女□ 提交于 2019-12-17 02:02:11
问题 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? 回答1: 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

Can we instantiate an abstract class?

情到浓时终转凉″ 提交于 2019-12-16 19:57:29
问题 During one of my interview, I was asked "If we can instantiate an abstract class?" My reply was "No. we can't". But, interviewer told me "Wrong, we can." I argued a bit on this. Then he told me to try this myself at home. abstract class my { public void mymethod() { System.out.print("Abstract"); } } class poly { public static void main(String a[]) { my m = new my() {}; m.mymethod(); } } Here, I'm creating instance of my class and calling method of abstract class. Can anyone please explain

Abstract Data Types vs. Parametric Polymorphism in Haskell

不打扰是莪最后的温柔 提交于 2019-12-14 04:18:21
问题 I am trying to get a grip on the relationship between these two concepts. First consider an example of an Abstract Data Type : data Tree a = Nil | Node { left :: Tree a, value :: a, right :: Tree a } According to Haskell wiki: This type is abstract because it leaves some aspects of its structure undefined, to be provided by the user of the data type. This is a weak form of abstract data type. Source Now consider the notion of parametric polymorphism : Parametric polymorphism refers to when

Abstract class and methods, Why?

痴心易碎 提交于 2019-12-13 08:02:16
问题 Hope anyone can help, i am learning Java and as comparable to anyone else in this forum i guess i am a newbie to programming as well. I have come across a chapter on abstract class and methods but don't really fully understand what they are used for and why, and thought i would get an explanation from someone who is an experienced programmer. Below i have example code i have been working on, with the help from this book, what i am not sure about is why in the class Dims do i have to have

How to display full docblocks for inherited methods in PhpDocumentor?

只愿长相守 提交于 2019-12-13 06:21:21
问题 I currently have code where there is an abstract parent class that defines some concrete methods, and the children classes extend this parent class, and will use the concrete methods. For example: <?php abstract class abstract_class { /** * I document foo. */ public function foo() { echo "I am the foo function!"; } } class child_class { /** * I document bar. */ public function bar() { echo "I am the bar function!"; } } ?> In my documentation for child_class, I see my bar() function well

How would an abstract render method work? (Java)

瘦欲@ 提交于 2019-12-13 02:57:51
问题 So say you want to have an abstract class called play, which has a render method. public abstract class RenderPanel{ public abstract void render(); } And then you have another class which calls the render method using some sort of game loop. public class Window implements Runnable{ public void run(){ while(running){ RenderPanel.render(); Thread.sleep(5000); } } } This code would not work because you cannot call an abstract class statically, and you can't instantiate the class. So how would

How can I generalize a custom type call function to an abstract type?

回眸只為那壹抹淺笑 提交于 2019-12-12 11:11:10
问题 I have the following mock setup, with an abstract type, concrete types as subtypes, and a function f which takes two arguments, the first being a Letter . abstract type Letter end struct A <: Letter end struct B <: Letter end f(::A, x) = ('a', x) f(::B, x) = ('b', x) a = A() b = B() I would like to define a custom call function for Letter subtypes which simply calls f . (t::A)(x) = f(t, x) (t::B)(x) = f(t, x) While this works, it seems quite redundant, especially considering that there could